@noya-app/noya-designsystem 0.1.74 → 0.1.75
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/.turbo/turbo-build.log +10 -10
- package/.turbo/turbo-lint.log +15 -1
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +61 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +61 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/combobox.test.ts +18 -0
- package/src/components/Combobox.tsx +48 -5
- package/src/utils/combobox.ts +41 -2
package/dist/index.mjs
CHANGED
|
@@ -10961,9 +10961,28 @@ var ComboboxState = class {
|
|
|
10961
10961
|
this.filter = this.lastSubmittedValue.itemName;
|
|
10962
10962
|
this.notifyChange();
|
|
10963
10963
|
}
|
|
10964
|
-
reset(newFilter = "") {
|
|
10964
|
+
reset(newFilter = "", options) {
|
|
10965
10965
|
this.filter = newFilter;
|
|
10966
|
-
|
|
10966
|
+
const filteredItems = this.getFilteredItems();
|
|
10967
|
+
const normalizedTitle = options?.selectedItemTitle ? options.selectedItemTitle.toString().toLowerCase() : void 0;
|
|
10968
|
+
const normalizedValue = options?.selectedItemValue ? options.selectedItemValue.toString().toLowerCase() : void 0;
|
|
10969
|
+
const matchedIndex = normalizedTitle || normalizedValue ? filteredItems.findIndex((item) => {
|
|
10970
|
+
if (!isSelectableMenuItem(item)) return false;
|
|
10971
|
+
const title = item.title?.toString().toLowerCase();
|
|
10972
|
+
const value = item.value?.toString().toLowerCase();
|
|
10973
|
+
if (normalizedValue && value === normalizedValue) return true;
|
|
10974
|
+
if (normalizedTitle && title === normalizedTitle) return true;
|
|
10975
|
+
return false;
|
|
10976
|
+
}) : -1;
|
|
10977
|
+
if (matchedIndex !== -1) {
|
|
10978
|
+
this.selectedIndex = matchedIndex;
|
|
10979
|
+
this.notifyChange();
|
|
10980
|
+
return;
|
|
10981
|
+
}
|
|
10982
|
+
const firstSelectableIndex = filteredItems.findIndex(
|
|
10983
|
+
(item) => isSelectableMenuItem(item)
|
|
10984
|
+
);
|
|
10985
|
+
this.selectedIndex = firstSelectableIndex === -1 ? 0 : firstSelectableIndex;
|
|
10967
10986
|
this.notifyChange();
|
|
10968
10987
|
}
|
|
10969
10988
|
getSelectedItem() {
|
|
@@ -11247,6 +11266,13 @@ var Combobox = memoGeneric(
|
|
|
11247
11266
|
}
|
|
11248
11267
|
}
|
|
11249
11268
|
const initialValueString = getInitialValueString();
|
|
11269
|
+
const resetSelectionOptions = useMemo28(
|
|
11270
|
+
() => props.mode === "string" ? { selectedItemTitle: initialValueString } : {
|
|
11271
|
+
selectedItemTitle: initialValueString,
|
|
11272
|
+
selectedItemValue: props.value?.value?.toString()
|
|
11273
|
+
},
|
|
11274
|
+
[initialValueString, props.mode, props.value]
|
|
11275
|
+
);
|
|
11250
11276
|
const [comboboxState] = useState27(
|
|
11251
11277
|
() => new ComboboxState(
|
|
11252
11278
|
items,
|
|
@@ -11257,6 +11283,7 @@ var Combobox = memoGeneric(
|
|
|
11257
11283
|
const state = useComboboxState(comboboxState);
|
|
11258
11284
|
const [isFocused, setIsFocused] = useState27(false);
|
|
11259
11285
|
const listRef = useRef21(null);
|
|
11286
|
+
const menuOpenedRef = useRef21(false);
|
|
11260
11287
|
const [shouldBlur, setShouldBlur] = useState27(false);
|
|
11261
11288
|
const { fieldId: id } = useLabel({
|
|
11262
11289
|
fieldId: rest.id
|
|
@@ -11274,9 +11301,20 @@ var Combobox = memoGeneric(
|
|
|
11274
11301
|
listRef.current.scrollToIndex(selectedIndex);
|
|
11275
11302
|
}
|
|
11276
11303
|
}, [selectedIndex]);
|
|
11304
|
+
useEffect20(() => {
|
|
11305
|
+
if (!shouldShowMenu) {
|
|
11306
|
+
menuOpenedRef.current = false;
|
|
11307
|
+
return;
|
|
11308
|
+
}
|
|
11309
|
+
if (menuOpenedRef.current) return;
|
|
11310
|
+
menuOpenedRef.current = true;
|
|
11311
|
+
if (listRef.current) {
|
|
11312
|
+
listRef.current.scrollToIndex(selectedIndex);
|
|
11313
|
+
}
|
|
11314
|
+
}, [shouldShowMenu, selectedIndex]);
|
|
11277
11315
|
const handleBlur = useCallback28(() => {
|
|
11278
11316
|
ref.current?.blur();
|
|
11279
|
-
comboboxState.reset(initialValueString);
|
|
11317
|
+
comboboxState.reset(initialValueString, resetSelectionOptions);
|
|
11280
11318
|
if (props.mode === "string") {
|
|
11281
11319
|
props.onBlur?.(
|
|
11282
11320
|
state.filter === state.lastSubmittedValue.filter,
|
|
@@ -11292,12 +11330,20 @@ var Combobox = memoGeneric(
|
|
|
11292
11330
|
}
|
|
11293
11331
|
}
|
|
11294
11332
|
setIsFocused(false);
|
|
11295
|
-
}, [
|
|
11333
|
+
}, [
|
|
11334
|
+
filter,
|
|
11335
|
+
initialValueString,
|
|
11336
|
+
props,
|
|
11337
|
+
resetSelectionOptions,
|
|
11338
|
+
state,
|
|
11339
|
+
comboboxState
|
|
11340
|
+
]);
|
|
11296
11341
|
const handleFocus = useCallback28(
|
|
11297
11342
|
(event) => {
|
|
11298
11343
|
setIsFocused(true);
|
|
11299
11344
|
comboboxState.reset(
|
|
11300
|
-
openMenuBehavior === "showAllItems" ? "" : initialValueString
|
|
11345
|
+
openMenuBehavior === "showAllItems" ? "" : initialValueString,
|
|
11346
|
+
resetSelectionOptions
|
|
11301
11347
|
);
|
|
11302
11348
|
if (ref.current) {
|
|
11303
11349
|
const length = ref.current.value.length;
|
|
@@ -11305,7 +11351,13 @@ var Combobox = memoGeneric(
|
|
|
11305
11351
|
}
|
|
11306
11352
|
onFocus?.(event);
|
|
11307
11353
|
},
|
|
11308
|
-
[
|
|
11354
|
+
[
|
|
11355
|
+
initialValueString,
|
|
11356
|
+
onFocus,
|
|
11357
|
+
openMenuBehavior,
|
|
11358
|
+
resetSelectionOptions,
|
|
11359
|
+
comboboxState
|
|
11360
|
+
]
|
|
11309
11361
|
);
|
|
11310
11362
|
const handleUpdateSelection = useCallback28(
|
|
11311
11363
|
(item) => {
|
|
@@ -11470,7 +11522,8 @@ var Combobox = memoGeneric(
|
|
|
11470
11522
|
return;
|
|
11471
11523
|
}
|
|
11472
11524
|
comboboxState.reset(
|
|
11473
|
-
openMenuBehavior === "showAllItems" ? "" : initialValueString
|
|
11525
|
+
openMenuBehavior === "showAllItems" ? "" : initialValueString,
|
|
11526
|
+
resetSelectionOptions
|
|
11474
11527
|
);
|
|
11475
11528
|
ref.current?.focus();
|
|
11476
11529
|
},
|
|
@@ -11479,6 +11532,7 @@ var Combobox = memoGeneric(
|
|
|
11479
11532
|
openMenuBehavior,
|
|
11480
11533
|
initialValueString,
|
|
11481
11534
|
handleBlur,
|
|
11535
|
+
resetSelectionOptions,
|
|
11482
11536
|
comboboxState
|
|
11483
11537
|
]
|
|
11484
11538
|
);
|