@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 +45 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +40 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1898,6 +1898,7 @@ type SelectOption<D = unknown, V extends string | number | boolean = string, L e
|
|
|
1898
1898
|
description?: string | ReactNode;
|
|
1899
1899
|
isDisabled?: boolean;
|
|
1900
1900
|
readOnly?: boolean;
|
|
1901
|
+
isPrefilled?: boolean;
|
|
1901
1902
|
};
|
|
1902
1903
|
type SelectorOption<T extends string | number | boolean = string> = {
|
|
1903
1904
|
value: T;
|
package/dist/index.d.ts
CHANGED
|
@@ -1898,6 +1898,7 @@ type SelectOption<D = unknown, V extends string | number | boolean = string, L e
|
|
|
1898
1898
|
description?: string | ReactNode;
|
|
1899
1899
|
isDisabled?: boolean;
|
|
1900
1900
|
readOnly?: boolean;
|
|
1901
|
+
isPrefilled?: boolean;
|
|
1901
1902
|
};
|
|
1902
1903
|
type SelectorOption<T extends string | number | boolean = string> = {
|
|
1903
1904
|
value: T;
|
package/dist/index.js
CHANGED
|
@@ -13217,7 +13217,10 @@ function useSelectState(params) {
|
|
|
13217
13217
|
() => resolveValueLabel(singleSelected, getValueLabel),
|
|
13218
13218
|
[singleSelected, getValueLabel]
|
|
13219
13219
|
);
|
|
13220
|
-
const
|
|
13220
|
+
const isSearchOnlyInput = isMulti || Boolean(isSearchInDropdown);
|
|
13221
|
+
const [inputValue, setInputValue] = React48.useState(
|
|
13222
|
+
isSearchOnlyInput ? "" : valueLabel
|
|
13223
|
+
);
|
|
13221
13224
|
const hasValue = selectedOptions.length > 0;
|
|
13222
13225
|
const isBlocked = Boolean(disabled) || Boolean(loading) || Boolean(readOnly);
|
|
13223
13226
|
const hasInvalidState = Boolean(error);
|
|
@@ -13232,18 +13235,18 @@ function useSelectState(params) {
|
|
|
13232
13235
|
const ids = useSelectIds({ name, hasValue, error, hideErrorMessage });
|
|
13233
13236
|
const { listboxId, getOptionId: getOptionId2 } = ids;
|
|
13234
13237
|
React48.useEffect(() => {
|
|
13235
|
-
if (
|
|
13238
|
+
if (isSearchOnlyInput) return;
|
|
13236
13239
|
if (!isFocused) setInputValue(valueLabel);
|
|
13237
|
-
}, [valueLabel, isFocused,
|
|
13240
|
+
}, [valueLabel, isFocused, isSearchOnlyInput]);
|
|
13238
13241
|
React48.useEffect(() => {
|
|
13239
|
-
if (!
|
|
13242
|
+
if (!isSearchOnlyInput) return;
|
|
13240
13243
|
if (!isOpen) {
|
|
13241
13244
|
setInputValue("");
|
|
13242
13245
|
setHighlightedIndex(-1);
|
|
13243
13246
|
}
|
|
13244
|
-
}, [isOpen,
|
|
13247
|
+
}, [isOpen, isSearchOnlyInput]);
|
|
13245
13248
|
const trimmedInput = inputValue.trim();
|
|
13246
|
-
const isFiltering =
|
|
13249
|
+
const isFiltering = isSearchOnlyInput ? trimmedInput.length > 0 : trimmedInput.length > 0 && trimmedInput.toLowerCase() !== valueLabel.toLowerCase();
|
|
13247
13250
|
const filteredOptions = React48.useMemo(() => {
|
|
13248
13251
|
if (!isFiltering) return options;
|
|
13249
13252
|
return options.filter((option) => filterOption(option, trimmedInput));
|
|
@@ -13304,7 +13307,7 @@ function useSelectState(params) {
|
|
|
13304
13307
|
return;
|
|
13305
13308
|
}
|
|
13306
13309
|
onSelectionChange([option], { action: "select" });
|
|
13307
|
-
setInputValue(resolveValueLabel(option, getValueLabel));
|
|
13310
|
+
setInputValue(isSearchInDropdown ? "" : resolveValueLabel(option, getValueLabel));
|
|
13308
13311
|
setIsOpen(false);
|
|
13309
13312
|
setIsFocused(false);
|
|
13310
13313
|
inputRef.current?.blur();
|
|
@@ -13317,7 +13320,8 @@ function useSelectState(params) {
|
|
|
13317
13320
|
onSelectionChange,
|
|
13318
13321
|
closeMenuOnSelect,
|
|
13319
13322
|
setIsOpen,
|
|
13320
|
-
getValueLabel
|
|
13323
|
+
getValueLabel,
|
|
13324
|
+
isSearchInDropdown
|
|
13321
13325
|
]
|
|
13322
13326
|
);
|
|
13323
13327
|
const removeOption = React48.useCallback(
|
|
@@ -13352,7 +13356,7 @@ function useSelectState(params) {
|
|
|
13352
13356
|
return;
|
|
13353
13357
|
}
|
|
13354
13358
|
onSelectionChange([newOption], { action: "create" });
|
|
13355
|
-
setInputValue(resolveValueLabel(newOption, getValueLabel));
|
|
13359
|
+
setInputValue(isSearchInDropdown ? "" : resolveValueLabel(newOption, getValueLabel));
|
|
13356
13360
|
setIsOpen(false);
|
|
13357
13361
|
setIsFocused(false);
|
|
13358
13362
|
inputRef.current?.blur();
|
|
@@ -13365,7 +13369,8 @@ function useSelectState(params) {
|
|
|
13365
13369
|
selectedOptions,
|
|
13366
13370
|
closeMenuOnSelect,
|
|
13367
13371
|
setIsOpen,
|
|
13368
|
-
getValueLabel
|
|
13372
|
+
getValueLabel,
|
|
13373
|
+
isSearchInDropdown
|
|
13369
13374
|
]);
|
|
13370
13375
|
const handleInputChange = React48.useCallback(
|
|
13371
13376
|
(event) => {
|
|
@@ -13391,10 +13396,10 @@ function useSelectState(params) {
|
|
|
13391
13396
|
(event) => {
|
|
13392
13397
|
if (containerRef.current?.contains(event.relatedTarget)) return;
|
|
13393
13398
|
setIsFocused(false);
|
|
13394
|
-
if (!
|
|
13399
|
+
if (!isSearchOnlyInput) setInputValue(valueLabel);
|
|
13395
13400
|
onBlur?.(event);
|
|
13396
13401
|
},
|
|
13397
|
-
[containerRef,
|
|
13402
|
+
[containerRef, isSearchOnlyInput, valueLabel, onBlur]
|
|
13398
13403
|
);
|
|
13399
13404
|
const handleInputKeyDown = React48.useCallback(
|
|
13400
13405
|
(event) => {
|
|
@@ -13448,7 +13453,7 @@ function useSelectState(params) {
|
|
|
13448
13453
|
}
|
|
13449
13454
|
if (event.key === "Escape") {
|
|
13450
13455
|
event.preventDefault();
|
|
13451
|
-
if (!
|
|
13456
|
+
if (!isSearchOnlyInput) setInputValue(valueLabel);
|
|
13452
13457
|
setIsOpen(false);
|
|
13453
13458
|
inputRef.current?.blur();
|
|
13454
13459
|
}
|
|
@@ -13456,6 +13461,7 @@ function useSelectState(params) {
|
|
|
13456
13461
|
[
|
|
13457
13462
|
onKeyDown,
|
|
13458
13463
|
isMulti,
|
|
13464
|
+
isSearchOnlyInput,
|
|
13459
13465
|
inputValue,
|
|
13460
13466
|
selectedOptions,
|
|
13461
13467
|
onSelectionChange,
|
|
@@ -13793,6 +13799,21 @@ function mergeComponents(overrides) {
|
|
|
13793
13799
|
};
|
|
13794
13800
|
}
|
|
13795
13801
|
|
|
13802
|
+
// src/dashboard/select/useSetCorrectOptionIfThereIsOnlyValue.ts
|
|
13803
|
+
import { useEffect as useEffect39 } from "react";
|
|
13804
|
+
function useSetCorrectOptionIfThereIsOnlyValue({ value, options, onChange, enabled = true }) {
|
|
13805
|
+
useEffect39(() => {
|
|
13806
|
+
if (!enabled || !value || !onChange || !options?.length) return;
|
|
13807
|
+
if (value.value === void 0 || value.value === null) return;
|
|
13808
|
+
if (value.label !== "NONE" && value.label !== "") return;
|
|
13809
|
+
const validOption = flattenGroupedOptions(options).find(
|
|
13810
|
+
(option) => option.value === value.value
|
|
13811
|
+
);
|
|
13812
|
+
if (!validOption) return;
|
|
13813
|
+
onChange({ ...validOption, isPrefilled: true }, { action: "select" });
|
|
13814
|
+
}, [enabled, onChange, options, value]);
|
|
13815
|
+
}
|
|
13816
|
+
|
|
13796
13817
|
// src/dashboard/select/Select.tsx
|
|
13797
13818
|
import { jsx as jsx156, jsxs as jsxs99 } from "react/jsx-runtime";
|
|
13798
13819
|
function SelectInternal(props, ref) {
|
|
@@ -13853,6 +13874,12 @@ function SelectInternal(props, ref) {
|
|
|
13853
13874
|
return props.defaultValue ?? null;
|
|
13854
13875
|
});
|
|
13855
13876
|
const currentValue = isControlled ? props.value : internalValue;
|
|
13877
|
+
useSetCorrectOptionIfThereIsOnlyValue({
|
|
13878
|
+
enabled: !isMulti,
|
|
13879
|
+
value: !isMulti ? props.value : void 0,
|
|
13880
|
+
options,
|
|
13881
|
+
onChange: !isMulti ? props.onChange : void 0
|
|
13882
|
+
});
|
|
13856
13883
|
const selectedOptions = React49.useMemo(() => {
|
|
13857
13884
|
if (isMulti) return currentValue ?? [];
|
|
13858
13885
|
return currentValue ? [currentValue] : [];
|