@leafygreen-ui/combobox 1.0.2 → 1.0.3
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/CHANGELOG.md +13 -0
- package/dist/Combobox.d.ts.map +1 -1
- package/dist/Combobox.types.d.ts.map +1 -1
- package/dist/ComboboxOption.d.ts.map +1 -1
- package/dist/ComboboxTestUtils.d.ts +2 -2
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/Combobox.spec.tsx +14 -25
- package/src/Combobox.story.tsx +1 -1
- package/src/Combobox.tsx +16 -19
- package/src/Combobox.types.ts +3 -2
- package/src/ComboboxOption.tsx +2 -3
- package/tsconfig.tsbuildinfo +1 -3977
package/src/Combobox.spec.tsx
CHANGED
|
@@ -337,13 +337,10 @@ describe('packages/combobox', () => {
|
|
|
337
337
|
|
|
338
338
|
testMultiSelect('Updating `value` updates the chips', () => {
|
|
339
339
|
let value = ['apple', 'banana'];
|
|
340
|
-
const {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
} = renderCombobox(select, {
|
|
345
|
-
value,
|
|
346
|
-
});
|
|
340
|
+
const { queryChipsByName, queryAllChips, rerenderCombobox } =
|
|
341
|
+
renderCombobox(select, {
|
|
342
|
+
value,
|
|
343
|
+
});
|
|
347
344
|
waitFor(() => {
|
|
348
345
|
const allChips = queryChipsByName(['Apple', 'Banana']);
|
|
349
346
|
allChips?.forEach(chip => expect(chip).toBeInTheDocument());
|
|
@@ -539,12 +536,8 @@ describe('packages/combobox', () => {
|
|
|
539
536
|
testSingleSelect(
|
|
540
537
|
'Clicking the combobox after making a selection should re-open the menu',
|
|
541
538
|
async () => {
|
|
542
|
-
const {
|
|
543
|
-
|
|
544
|
-
inputEl,
|
|
545
|
-
openMenu,
|
|
546
|
-
getMenuElements,
|
|
547
|
-
} = renderCombobox(select);
|
|
539
|
+
const { comboboxEl, inputEl, openMenu, getMenuElements } =
|
|
540
|
+
renderCombobox(select);
|
|
548
541
|
const { optionElements, menuContainerEl } = openMenu();
|
|
549
542
|
const firstOption = optionElements![0];
|
|
550
543
|
userEvent.click(firstOption);
|
|
@@ -685,9 +678,8 @@ describe('packages/combobox', () => {
|
|
|
685
678
|
|
|
686
679
|
describe('Enter key', () => {
|
|
687
680
|
test('selects highlighted option', () => {
|
|
688
|
-
const { inputEl, openMenu, queryChipsByName } =
|
|
689
|
-
select
|
|
690
|
-
);
|
|
681
|
+
const { inputEl, openMenu, queryChipsByName } =
|
|
682
|
+
renderCombobox(select);
|
|
691
683
|
openMenu();
|
|
692
684
|
userEvent.type(inputEl!, '{arrowdown}{enter}');
|
|
693
685
|
if (select === 'multiple') {
|
|
@@ -698,9 +690,8 @@ describe('packages/combobox', () => {
|
|
|
698
690
|
});
|
|
699
691
|
|
|
700
692
|
testSingleSelect('Re-opens menu after making a selection', async () => {
|
|
701
|
-
const { inputEl, openMenu, getMenuElements } =
|
|
702
|
-
'single'
|
|
703
|
-
);
|
|
693
|
+
const { inputEl, openMenu, getMenuElements } =
|
|
694
|
+
renderCombobox('single');
|
|
704
695
|
const { optionElements, menuContainerEl } = openMenu();
|
|
705
696
|
const firstOption = optionElements![0];
|
|
706
697
|
userEvent.click(firstOption);
|
|
@@ -797,9 +788,8 @@ describe('packages/combobox', () => {
|
|
|
797
788
|
);
|
|
798
789
|
|
|
799
790
|
testSingleSelect('Re-opens menu after making a selection', async () => {
|
|
800
|
-
const { inputEl, openMenu, getMenuElements } =
|
|
801
|
-
'single'
|
|
802
|
-
);
|
|
791
|
+
const { inputEl, openMenu, getMenuElements } =
|
|
792
|
+
renderCombobox('single');
|
|
803
793
|
const { optionElements, menuContainerEl } = openMenu();
|
|
804
794
|
const firstOption = optionElements![0];
|
|
805
795
|
userEvent.click(firstOption);
|
|
@@ -1054,9 +1044,8 @@ describe('packages/combobox', () => {
|
|
|
1054
1044
|
testSingleSelect(
|
|
1055
1045
|
'Opens the menu after making a selection',
|
|
1056
1046
|
async () => {
|
|
1057
|
-
const { inputEl, openMenu, getMenuElements } =
|
|
1058
|
-
select
|
|
1059
|
-
);
|
|
1047
|
+
const { inputEl, openMenu, getMenuElements } =
|
|
1048
|
+
renderCombobox(select);
|
|
1060
1049
|
const { optionElements, menuContainerEl } = openMenu();
|
|
1061
1050
|
const firstOption = optionElements![0];
|
|
1062
1051
|
userEvent.click(firstOption);
|
package/src/Combobox.story.tsx
CHANGED
package/src/Combobox.tsx
CHANGED
|
@@ -222,10 +222,10 @@ export default function Combobox<M extends boolean>({
|
|
|
222
222
|
[filteredOptions, getDisplayNameForValue, inputValue],
|
|
223
223
|
);
|
|
224
224
|
|
|
225
|
-
const visibleOptions = useMemo(
|
|
226
|
-
allOptions,
|
|
227
|
-
isOptionVisible,
|
|
228
|
-
|
|
225
|
+
const visibleOptions = useMemo(
|
|
226
|
+
() => allOptions.filter(isOptionVisible),
|
|
227
|
+
[allOptions, isOptionVisible],
|
|
228
|
+
);
|
|
229
229
|
|
|
230
230
|
const isValueValid = useCallback(
|
|
231
231
|
(value: string | null): boolean => {
|
|
@@ -508,10 +508,8 @@ export default function Combobox<M extends boolean>({
|
|
|
508
508
|
|
|
509
509
|
if (focusedElementRef && focusedElementRef.current && menuRef.current) {
|
|
510
510
|
const { offsetTop: optionTop } = focusedElementRef.current;
|
|
511
|
-
const {
|
|
512
|
-
|
|
513
|
-
offsetHeight: menuHeight,
|
|
514
|
-
} = menuRef.current;
|
|
511
|
+
const { scrollTop: menuScroll, offsetHeight: menuHeight } =
|
|
512
|
+
menuRef.current;
|
|
515
513
|
|
|
516
514
|
if (optionTop > menuHeight || optionTop < menuScroll) {
|
|
517
515
|
menuRef.current.scrollTop = optionTop;
|
|
@@ -594,10 +592,10 @@ export default function Combobox<M extends boolean>({
|
|
|
594
592
|
],
|
|
595
593
|
);
|
|
596
594
|
|
|
597
|
-
const renderedOptions = useMemo(
|
|
598
|
-
children,
|
|
599
|
-
renderInternalOptions,
|
|
600
|
-
|
|
595
|
+
const renderedOptions = useMemo(
|
|
596
|
+
() => renderInternalOptions(children),
|
|
597
|
+
[children, renderInternalOptions],
|
|
598
|
+
);
|
|
601
599
|
|
|
602
600
|
const renderedChips = useMemo(() => {
|
|
603
601
|
if (isMultiselect(selection)) {
|
|
@@ -687,9 +685,10 @@ export default function Combobox<M extends boolean>({
|
|
|
687
685
|
]);
|
|
688
686
|
|
|
689
687
|
// Do any of the options have an icon?
|
|
690
|
-
const withIcons = useMemo(
|
|
691
|
-
allOptions,
|
|
692
|
-
|
|
688
|
+
const withIcons = useMemo(
|
|
689
|
+
() => allOptions.some(opt => opt.hasGlyph),
|
|
690
|
+
[allOptions],
|
|
691
|
+
);
|
|
693
692
|
|
|
694
693
|
/**
|
|
695
694
|
*
|
|
@@ -859,10 +858,8 @@ export default function Combobox<M extends boolean>({
|
|
|
859
858
|
const menuMargin = 8;
|
|
860
859
|
|
|
861
860
|
if (viewportSize && comboboxRef.current && menuRef.current) {
|
|
862
|
-
const {
|
|
863
|
-
|
|
864
|
-
bottom: triggerBottom,
|
|
865
|
-
} = comboboxRef.current.getBoundingClientRect();
|
|
861
|
+
const { top: triggerTop, bottom: triggerBottom } =
|
|
862
|
+
comboboxRef.current.getBoundingClientRect();
|
|
866
863
|
|
|
867
864
|
// Find out how much space is available above or below the trigger
|
|
868
865
|
const safeSpace = Math.max(
|
package/src/Combobox.types.ts
CHANGED
|
@@ -16,7 +16,8 @@ export const TrunctationLocation = {
|
|
|
16
16
|
end: 'end',
|
|
17
17
|
none: 'none',
|
|
18
18
|
} as const;
|
|
19
|
-
export type TrunctationLocation =
|
|
19
|
+
export type TrunctationLocation =
|
|
20
|
+
typeof TrunctationLocation[keyof typeof TrunctationLocation];
|
|
20
21
|
|
|
21
22
|
export const Overflow = {
|
|
22
23
|
expandY: 'expand-y',
|
|
@@ -55,7 +56,7 @@ export function getNullSelection<M extends boolean>(
|
|
|
55
56
|
multiselect: M,
|
|
56
57
|
): SelectValueType<M> {
|
|
57
58
|
if (multiselect) {
|
|
58
|
-
return
|
|
59
|
+
return [] as Array<string> as SelectValueType<M>;
|
|
59
60
|
} else {
|
|
60
61
|
return null as SelectValueType<M>;
|
|
61
62
|
}
|
package/src/ComboboxOption.tsx
CHANGED
|
@@ -91,9 +91,8 @@ const InternalComboboxOption = React.forwardRef<
|
|
|
91
91
|
}: InternalComboboxOptionProps,
|
|
92
92
|
forwardedRef,
|
|
93
93
|
) => {
|
|
94
|
-
const { multiselect, darkMode, withIcons, inputValue } =
|
|
95
|
-
ComboboxContext
|
|
96
|
-
);
|
|
94
|
+
const { multiselect, darkMode, withIcons, inputValue } =
|
|
95
|
+
useContext(ComboboxContext);
|
|
97
96
|
const optionTextId = useIdAllocator({ prefix: 'combobox-option-text' });
|
|
98
97
|
const optionRef = useForwardedRef(forwardedRef, null);
|
|
99
98
|
|