UNPKG

@workday/canvas-kit-react

Version:

The parent module that contains all Workday Canvas Kit React components

34 lines (33 loc) 1.57 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.useComboboxInputArbitrary = void 0; const react_1 = __importDefault(require("react")); const common_1 = require("@workday/canvas-kit-react/common"); const useComboboxModel_1 = require("./useComboboxModel"); /** * An arbitrary combobox can have any value. The list of options are suggestions to aid the user in * entering values. A Typeahead or Autocomplete are examples are arbitrary value comboboxes. */ exports.useComboboxInputArbitrary = (0, common_1.createElemPropsHook)(useComboboxModel_1.useComboboxModel)((model, ref) => { const { elementRef, localRef } = (0, common_1.useLocalRef)(ref); // sync model selection state with inputs react_1.default.useLayoutEffect(() => { if (localRef.current) { const formValue = (model.state.selectedIds === 'all' ? [] : model.state.selectedIds).join(', '); if (formValue !== localRef.current.value) { (0, common_1.dispatchInputEvent)(localRef.current, formValue); } } }, [model.state.selectedIds, localRef]); return { ref: elementRef, onChange: (event) => { var _a, _b; (_a = model.onChange) === null || _a === void 0 ? void 0 : _a.call(model, event); (_b = model.onFilterChange) === null || _b === void 0 ? void 0 : _b.call(model, event); }, }; });