@scripso-homepad/ui 0.4.21 → 0.4.22
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 +5 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Select.stories.tsx +1 -0
- package/src/components/Select.tsx +9 -2
package/package.json
CHANGED
|
@@ -214,6 +214,11 @@ interface SelectBaseProps {
|
|
|
214
214
|
hintClassName?: string;
|
|
215
215
|
/** Shorter option rows for compact filter-style dropdowns. */
|
|
216
216
|
compact?: boolean;
|
|
217
|
+
/**
|
|
218
|
+
* When true (default), clicking the already-selected option clears the selection
|
|
219
|
+
* in single-select mode. Set to false for required fields that must keep a value.
|
|
220
|
+
*/
|
|
221
|
+
allowDeselect?: boolean;
|
|
217
222
|
}
|
|
218
223
|
|
|
219
224
|
export interface SingleSelectProps extends SelectBaseProps {
|
|
@@ -266,6 +271,7 @@ export function Select({
|
|
|
266
271
|
errorClassName,
|
|
267
272
|
hintClassName,
|
|
268
273
|
compact = false,
|
|
274
|
+
allowDeselect = true,
|
|
269
275
|
}: SelectProps) {
|
|
270
276
|
const wrapperRef = useRef<ComponentRef<typeof View>>(null);
|
|
271
277
|
const triggerRef = useRef<ComponentRef<typeof Pressable>>(null);
|
|
@@ -389,9 +395,10 @@ export function Select({
|
|
|
389
395
|
return;
|
|
390
396
|
}
|
|
391
397
|
|
|
392
|
-
// Keep the current value when the selected option is clicked again.
|
|
393
|
-
// Clearing to "" breaks required selects (e.g. language) and shows the placeholder.
|
|
394
398
|
if (selectedValues.includes(nextValue)) {
|
|
399
|
+
if (allowDeselect) {
|
|
400
|
+
(onValueChange as SingleSelectProps["onValueChange"] | undefined)?.("");
|
|
401
|
+
}
|
|
395
402
|
closeMenu();
|
|
396
403
|
return;
|
|
397
404
|
}
|