@chekinapp/ui 0.0.122 → 0.0.123

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.
package/dist/index.cjs CHANGED
@@ -13577,7 +13577,10 @@ function useSelectState(params) {
13577
13577
  () => resolveValueLabel(singleSelected, getValueLabel),
13578
13578
  [singleSelected, getValueLabel]
13579
13579
  );
13580
- const [inputValue, setInputValue] = React48.useState(isMulti ? "" : valueLabel);
13580
+ const isSearchOnlyInput = isMulti || Boolean(isSearchInDropdown);
13581
+ const [inputValue, setInputValue] = React48.useState(
13582
+ isSearchOnlyInput ? "" : valueLabel
13583
+ );
13581
13584
  const hasValue = selectedOptions.length > 0;
13582
13585
  const isBlocked = Boolean(disabled) || Boolean(loading) || Boolean(readOnly);
13583
13586
  const hasInvalidState = Boolean(error);
@@ -13592,18 +13595,18 @@ function useSelectState(params) {
13592
13595
  const ids = useSelectIds({ name, hasValue, error, hideErrorMessage });
13593
13596
  const { listboxId, getOptionId: getOptionId2 } = ids;
13594
13597
  React48.useEffect(() => {
13595
- if (isMulti) return;
13598
+ if (isSearchOnlyInput) return;
13596
13599
  if (!isFocused) setInputValue(valueLabel);
13597
- }, [valueLabel, isFocused, isMulti]);
13600
+ }, [valueLabel, isFocused, isSearchOnlyInput]);
13598
13601
  React48.useEffect(() => {
13599
- if (!isMulti) return;
13602
+ if (!isSearchOnlyInput) return;
13600
13603
  if (!isOpen) {
13601
13604
  setInputValue("");
13602
13605
  setHighlightedIndex(-1);
13603
13606
  }
13604
- }, [isOpen, isMulti]);
13607
+ }, [isOpen, isSearchOnlyInput]);
13605
13608
  const trimmedInput = inputValue.trim();
13606
- const isFiltering = isMulti ? trimmedInput.length > 0 : trimmedInput.length > 0 && trimmedInput.toLowerCase() !== valueLabel.toLowerCase();
13609
+ const isFiltering = isSearchOnlyInput ? trimmedInput.length > 0 : trimmedInput.length > 0 && trimmedInput.toLowerCase() !== valueLabel.toLowerCase();
13607
13610
  const filteredOptions = React48.useMemo(() => {
13608
13611
  if (!isFiltering) return options;
13609
13612
  return options.filter((option) => filterOption(option, trimmedInput));
@@ -13664,7 +13667,7 @@ function useSelectState(params) {
13664
13667
  return;
13665
13668
  }
13666
13669
  onSelectionChange([option], { action: "select" });
13667
- setInputValue(resolveValueLabel(option, getValueLabel));
13670
+ setInputValue(isSearchInDropdown ? "" : resolveValueLabel(option, getValueLabel));
13668
13671
  setIsOpen(false);
13669
13672
  setIsFocused(false);
13670
13673
  inputRef.current?.blur();
@@ -13677,7 +13680,8 @@ function useSelectState(params) {
13677
13680
  onSelectionChange,
13678
13681
  closeMenuOnSelect,
13679
13682
  setIsOpen,
13680
- getValueLabel
13683
+ getValueLabel,
13684
+ isSearchInDropdown
13681
13685
  ]
13682
13686
  );
13683
13687
  const removeOption = React48.useCallback(
@@ -13712,7 +13716,7 @@ function useSelectState(params) {
13712
13716
  return;
13713
13717
  }
13714
13718
  onSelectionChange([newOption], { action: "create" });
13715
- setInputValue(resolveValueLabel(newOption, getValueLabel));
13719
+ setInputValue(isSearchInDropdown ? "" : resolveValueLabel(newOption, getValueLabel));
13716
13720
  setIsOpen(false);
13717
13721
  setIsFocused(false);
13718
13722
  inputRef.current?.blur();
@@ -13725,7 +13729,8 @@ function useSelectState(params) {
13725
13729
  selectedOptions,
13726
13730
  closeMenuOnSelect,
13727
13731
  setIsOpen,
13728
- getValueLabel
13732
+ getValueLabel,
13733
+ isSearchInDropdown
13729
13734
  ]);
13730
13735
  const handleInputChange = React48.useCallback(
13731
13736
  (event) => {
@@ -13751,10 +13756,10 @@ function useSelectState(params) {
13751
13756
  (event) => {
13752
13757
  if (containerRef.current?.contains(event.relatedTarget)) return;
13753
13758
  setIsFocused(false);
13754
- if (!isMulti) setInputValue(valueLabel);
13759
+ if (!isSearchOnlyInput) setInputValue(valueLabel);
13755
13760
  onBlur?.(event);
13756
13761
  },
13757
- [containerRef, isMulti, valueLabel, onBlur]
13762
+ [containerRef, isSearchOnlyInput, valueLabel, onBlur]
13758
13763
  );
13759
13764
  const handleInputKeyDown = React48.useCallback(
13760
13765
  (event) => {
@@ -13808,7 +13813,7 @@ function useSelectState(params) {
13808
13813
  }
13809
13814
  if (event.key === "Escape") {
13810
13815
  event.preventDefault();
13811
- if (!isMulti) setInputValue(valueLabel);
13816
+ if (!isSearchOnlyInput) setInputValue(valueLabel);
13812
13817
  setIsOpen(false);
13813
13818
  inputRef.current?.blur();
13814
13819
  }
@@ -13816,6 +13821,7 @@ function useSelectState(params) {
13816
13821
  [
13817
13822
  onKeyDown,
13818
13823
  isMulti,
13824
+ isSearchOnlyInput,
13819
13825
  inputValue,
13820
13826
  selectedOptions,
13821
13827
  onSelectionChange,
@@ -14153,6 +14159,21 @@ function mergeComponents(overrides) {
14153
14159
  };
14154
14160
  }
14155
14161
 
14162
+ // src/dashboard/select/useSetCorrectOptionIfThereIsOnlyValue.ts
14163
+ var import_react89 = require("react");
14164
+ function useSetCorrectOptionIfThereIsOnlyValue({ value, options, onChange, enabled = true }) {
14165
+ (0, import_react89.useEffect)(() => {
14166
+ if (!enabled || !value || !onChange || !options?.length) return;
14167
+ if (value.value === void 0 || value.value === null) return;
14168
+ if (value.label !== "NONE" && value.label !== "") return;
14169
+ const validOption = flattenGroupedOptions(options).find(
14170
+ (option) => option.value === value.value
14171
+ );
14172
+ if (!validOption) return;
14173
+ onChange({ ...validOption, isPrefilled: true }, { action: "select" });
14174
+ }, [enabled, onChange, options, value]);
14175
+ }
14176
+
14156
14177
  // src/dashboard/select/Select.tsx
14157
14178
  var import_jsx_runtime158 = require("react/jsx-runtime");
14158
14179
  function SelectInternal(props, ref) {
@@ -14213,6 +14234,12 @@ function SelectInternal(props, ref) {
14213
14234
  return props.defaultValue ?? null;
14214
14235
  });
14215
14236
  const currentValue = isControlled ? props.value : internalValue;
14237
+ useSetCorrectOptionIfThereIsOnlyValue({
14238
+ enabled: !isMulti,
14239
+ value: !isMulti ? props.value : void 0,
14240
+ options,
14241
+ onChange: !isMulti ? props.onChange : void 0
14242
+ });
14216
14243
  const selectedOptions = React49.useMemo(() => {
14217
14244
  if (isMulti) return currentValue ?? [];
14218
14245
  return currentValue ? [currentValue] : [];
@@ -17962,11 +17989,11 @@ function toastResponseError(error, options = {}) {
17962
17989
  }
17963
17990
 
17964
17991
  // src/legacy-fields/textarea/Textarea.tsx
17965
- var import_react89 = require("react");
17992
+ var import_react90 = require("react");
17966
17993
  var import_jsx_runtime182 = require("react/jsx-runtime");
17967
- var LegacyTextarea = (0, import_react89.forwardRef)(
17994
+ var LegacyTextarea = (0, import_react90.forwardRef)(
17968
17995
  ({ className, textareaClassName, label, disabled, name, invalid, ...textareaProps }, ref) => {
17969
- const inputId = (0, import_react89.useId)();
17996
+ const inputId = (0, import_react90.useId)();
17970
17997
  return /* @__PURE__ */ (0, import_jsx_runtime182.jsxs)("div", { className: cn("relative", className), children: [
17971
17998
  /* @__PURE__ */ (0, import_jsx_runtime182.jsx)(
17972
17999
  "textarea",
@@ -19786,7 +19813,7 @@ AirbnbPhoneField.displayName = "AirbnbPhoneField";
19786
19813
  var React80 = __toESM(require("react"), 1);
19787
19814
  var import_lucide_react57 = require("lucide-react");
19788
19815
  var import_react_virtual3 = require("@tanstack/react-virtual");
19789
- var import_react90 = require("react");
19816
+ var import_react91 = require("react");
19790
19817
  var import_jsx_runtime193 = require("react/jsx-runtime");
19791
19818
  var ROW_HEIGHT = 48;
19792
19819
  var DESKTOP_LIST_HEIGHT = 280;
@@ -19864,7 +19891,7 @@ var AirbnbSearchableSelectInternal = ({
19864
19891
  isDisabled: !open || isMobile3
19865
19892
  });
19866
19893
  const handleOnOpenChange = useEvent(onOpenChange);
19867
- const setSelectOpen = (0, import_react90.useCallback)(
19894
+ const setSelectOpen = (0, import_react91.useCallback)(
19868
19895
  (nextOpen, options2) => {
19869
19896
  setOpen(nextOpen);
19870
19897
  handleOnOpenChange?.(nextOpen);