@homebound/beam 2.338.0 → 2.339.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,6 +52,7 @@ export interface ComboBoxBaseProps<O, V extends Value> extends BeamFocusableProp
52
52
  unsetLabel?: string;
53
53
  hideErrorMessage?: boolean;
54
54
  multiline?: boolean;
55
+ onSearch?: (search: string) => void;
55
56
  }
56
57
  /**
57
58
  * Provides a non-native select/dropdown widget that allows the user to type to filter the options.
@@ -13,6 +13,7 @@ const ComboBoxInput_1 = require("./ComboBoxInput");
13
13
  const ListBox_1 = require("./ListBox");
14
14
  const Value_1 = require("../Value");
15
15
  const utils_1 = require("../utils");
16
+ const use_debounce_1 = require("use-debounce");
16
17
  /**
17
18
  * Provides a non-native select/dropdown widget that allows the user to type to filter the options.
18
19
  *
@@ -25,7 +26,7 @@ const utils_1 = require("../utils");
25
26
  function ComboBoxBase(props) {
26
27
  var _a, _b, _c, _d, _e;
27
28
  const { fieldProps } = (0, PresentationContext_1.usePresentationContext)();
28
- const { disabled, readOnly, onSelect, options: propOptions, multiselect = false, values: propValues, nothingSelectedText = "", contrast, disabledOptions, borderless, unsetLabel, getOptionLabel: propOptionLabel, getOptionValue: propOptionValue, getOptionMenuLabel: propOptionMenuLabel, fullWidth = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.fullWidth) !== null && _a !== void 0 ? _a : false, ...otherProps } = props;
29
+ const { disabled, readOnly, onSelect, options: propOptions, multiselect = false, values: propValues, nothingSelectedText = "", contrast, disabledOptions, borderless, unsetLabel, getOptionLabel: propOptionLabel, getOptionValue: propOptionValue, getOptionMenuLabel: propOptionMenuLabel, fullWidth = (_a = fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.fullWidth) !== null && _a !== void 0 ? _a : false, onSearch, ...otherProps } = props;
29
30
  const labelStyle = (_c = (_b = otherProps.labelStyle) !== null && _b !== void 0 ? _b : fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.labelStyle) !== null && _c !== void 0 ? _c : "above";
30
31
  // Memoize the callback functions and handle the `unset` option if provided.
31
32
  const getOptionLabel = (0, react_1.useCallback)((o) => (unsetLabel && o === exports.unsetOption ? unsetLabel : propOptionLabel(o)),
@@ -166,8 +167,11 @@ function ComboBoxBase(props) {
166
167
  selectedKeys,
167
168
  onSelectionChange,
168
169
  });
170
+ const [debouncedSearch] = (0, use_debounce_1.useDebounce)(searchValue, 300);
169
171
  // Reset inputValue when closed or selected changes
170
172
  (0, react_1.useEffect)(() => {
173
+ if (debouncedSearch)
174
+ return;
171
175
  if (state.isOpen && multiselect) {
172
176
  // While the multiselect is open, let the user keep typing
173
177
  setFieldState((prevState) => ({
@@ -183,7 +187,11 @@ function ComboBoxBase(props) {
183
187
  inputValue: getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly),
184
188
  }));
185
189
  }
186
- }, [state.isOpen, selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly]);
190
+ }, [state.isOpen, selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly, debouncedSearch]);
191
+ // Call on search callback when the user types in the input field
192
+ (0, react_1.useEffect)(() => {
193
+ onSearch === null || onSearch === void 0 ? void 0 : onSearch(debouncedSearch !== null && debouncedSearch !== void 0 ? debouncedSearch : "");
194
+ }, [onSearch, debouncedSearch]);
187
195
  // For the most part, the returned props contain `aria-*` and `id` attributes for accessibility purposes.
188
196
  const { buttonProps: triggerProps, inputProps, listBoxProps, labelProps, } = (0, react_aria_1.useComboBox)({
189
197
  ...comboBoxProps,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.338.0",
3
+ "version": "2.339.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",