Skip to content

Commit

Permalink
fix: almost never allow ArrowUp for DropDown, always allow ArrowDown
Browse files Browse the repository at this point in the history
  • Loading branch information
cknabe committed Jan 21, 2025
1 parent 6489e55 commit 1714359
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions packages/react/src/components/Dropdown/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -549,18 +549,9 @@ const Dropdown = React.forwardRef(
);
}

// Allow any key press that is not ArrowUp or ArrowDown
const isNotUpOrDown = evt.key !== 'ArrowUp' && evt.key !== 'ArrowDown';
// Allow any key press other than ArrowUp if the first item is selected
const isNotTopAndUp =
evt.key === 'ArrowUp' && items?.[0] !== selectedItem;
// Allow any key press other than ArrowDown if the last item is selected
const isNotBottomAndDown =
evt.key === 'ArrowDown' &&
items?.[items?.length - 1] !== selectedItem;
if (
toggleButtonProps.onKeyDown &&
(isNotUpOrDown || isOpen || isNotTopAndUp || isNotBottomAndDown)
(evt.key !== 'ArrowUp' || (isOpen && evt.key === 'ArrowUp'))
) {
toggleButtonProps.onKeyDown(evt);
}
Expand Down

0 comments on commit 1714359

Please sign in to comment.