Skip to content

Commit 9f48228

Browse files
(Lookup): enable skipping selections
1 parent 1cf0c6e commit 9f48228

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/scripts/Lookup.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,7 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
301301

302302
// Set initial focus when dropdown opens
303303
useEffect(() => {
304-
if (opened && !focusedValue) {
305-
const initialFocus = getOptionValues()[0];
306-
setFocusedValue(initialFocus);
307-
scrollFocusedElementIntoView(initialFocus);
308-
} else if (!opened) {
304+
if (!opened) {
309305
setFocusedValue(undefined);
310306
}
311307
}, [opened, getOptionValues, focusedValue, scrollFocusedElementIntoView]);
@@ -377,6 +373,7 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
377373
onNavigateDown: () => void;
378374
onNavigateUp: () => void;
379375
onSelect: () => void;
376+
isIgnoreTabNavigation?: () => boolean;
380377
onTabNavigation?: (direction: 'forward' | 'backward') => void;
381378
}) => {
382379
return (e: KeyboardEvent<HTMLInputElement>) => {
@@ -401,6 +398,13 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
401398
} else if (e.keyCode === 9 && config.onTabNavigation) {
402399
// Tab or Shift+Tab
403400
if (config.opened) {
401+
if (
402+
config.isIgnoreTabNavigation &&
403+
config.isIgnoreTabNavigation()
404+
) {
405+
return;
406+
}
407+
404408
e.preventDefault();
405409
e.stopPropagation();
406410
config.onTabNavigation(e.shiftKey ? 'backward' : 'forward');
@@ -458,6 +462,9 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
458462
onLookupRequest_?.(searchText);
459463
}
460464
},
465+
isIgnoreTabNavigation: () => {
466+
return focusedValue === undefined;
467+
},
461468
onTabNavigation: (direction) => {
462469
const optionValues = getOptionValues();
463470
const currentIndex = focusedValue
@@ -553,6 +560,9 @@ export const Lookup = createFC<LookupProps, { isFormElement: boolean }>(
553560
setScopeOpened(!scopeOpened);
554561
}
555562
},
563+
isIgnoreTabNavigation: () => {
564+
return scopeFocusedIndex === -1;
565+
},
556566
onTabNavigation: (direction) => {
557567
if (!scopes) return;
558568
if (direction === 'backward') {

0 commit comments

Comments
 (0)