Skip to content

Commit

Permalink
remove nested conditional in key handler
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Nov 1, 2024
1 parent 414e7a4 commit 82b4b7c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/components/CustomDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,21 @@ const CustomDropdown: React.FC<CustomDropdownProps> = ({
* Manually handling keydown and hover behavior because
* our focus management overrides the defaults of the antd components.
*/
const openTriggers = new Set(["Enter", " ", "ArrowDown"]);

const handleKeyDown: KeyboardEventHandler<any> = (event) => {
if (dropdownState === DropdownState.CLOSED) {
if (
(event.key === "Enter" ||
event.key === " " ||
event.key === "ArrowDown") &&
!event.defaultPrevented
) {
event.preventDefault();
setDropdownState(DropdownState.FORCED_OPEN); // Opened by keyboard
}
} else if (event.key === "Escape") {
if (event.key === "Escape") {
event.preventDefault();
setDropdownState(DropdownState.CLOSED);
triggerRef.current?.focus();
}
if (
openTriggers.has(event.key) &&
dropdownState === DropdownState.CLOSED
) {
event.preventDefault();
setDropdownState(DropdownState.FORCED_OPEN); // Opened by keyboard
}
};

const handleMouseEnter = () => {
Expand Down

0 comments on commit 82b4b7c

Please sign in to comment.