@adaptabletools/adaptable-cjs
Version:
Powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
42 lines (41 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdaptableFormControlTextClear = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const StringExtensions_1 = require("../../../Utilities/Extensions/StringExtensions");
const FieldWrap_1 = tslib_1.__importDefault(require("../../../components/FieldWrap"));
const SimpleButton_1 = tslib_1.__importDefault(require("../../../components/SimpleButton"));
const Input_1 = tslib_1.__importDefault(require("../../../components/Input"));
const twMerge_1 = require("../../../twMerge");
exports.AdaptableFormControlTextClear = React.forwardRef((props, ref) => {
let closeButtonTooltip = props.value ? 'Clear' : null;
const inputRef = React.useRef(null);
const { focusOnClear = true } = props;
return (React.createElement(FieldWrap_1.default, { onClick: props.onClick, className: (0, twMerge_1.twMerge)('twa:bg-defaultbackground twa:overflow-visible twa:w-full', props.className), style: props.style },
React.createElement(Input_1.default, { "aria-label": props['aria-label'], autoFocus: props.autoFocus, style: props.inputStyle, className: props.inputClassName, ref: (r) => {
inputRef.current = r;
if (!ref) {
return;
}
if (typeof ref === 'function') {
ref(r);
}
else {
ref.current = r;
}
}, type: "text", placeholder: props.placeholder, value: props.value, onChange: (x) => props.OnTextChange(x.target.value) }),
props.actionTools,
React.createElement(SimpleButton_1.default, { variant: "text", icon: "close", tooltip: closeButtonTooltip, className: "twa:mr-1 twa:p-0", onClick: () => {
props.OnTextChange('');
const input = inputRef.current;
if (!focusOnClear) {
return;
}
requestAnimationFrame(() => {
if (input && input.focus) {
input.focus();
}
});
}, disabled: StringExtensions_1.StringExtensions.IsNullOrEmpty(props.value.toString()) })));
});