Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions packages/react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -531,16 +531,22 @@ const Dropdown = React.forwardRef(

const onKeyDownHandler = useCallback(
(evt: React.KeyboardEvent<HTMLButtonElement>) => {
if (
evt.code !== 'Space' ||
!['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)
) {
const navigationKeys = ['ArrowDown', 'ArrowUp', ' ', 'Enter'];

// If the key is not a navigation key, the user is typing
if (!navigationKeys.includes(evt.key)) {
setIsTyping(true);
}
if (
(isTyping && evt.code === 'Space') ||
!['ArrowDown', 'ArrowUp', ' ', 'Enter'].includes(evt.key)
) {
// Reset the timer for typing timeout
if (currTimer) {
clearTimeout(currTimer);
}
setCurrTimer(
setTimeout(() => {
setIsTyping(false);
}, 3000)
);
} else if (isTyping && evt.key === ' ') {
// If user is typing and presses space, reset the timer
if (currTimer) {
clearTimeout(currTimer);
}
Expand All @@ -550,6 +556,7 @@ const Dropdown = React.forwardRef(
}, 3000)
);
}

if (['ArrowDown'].includes(evt.key)) {
setIsFocused(false);
}
Expand Down
Loading