Skip to content

Commit

Permalink
fix(hooks): resolve type error in onKeyDown event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaic4o committed May 23, 2024
1 parent 06ecd21 commit 54990e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-turkeys-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/use-aria-menu": major
---

WHAT: Fixed a type error in the onKeyDown event handler for the menu component. WHY: The current implementation uses @ts-ignore to suppress type errors in the onKeyDown event handler. This may result in reduced type safety.
13 changes: 6 additions & 7 deletions packages/hooks/use-aria-menu/src/use-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import {AriaMenuProps} from "@react-types/menu";
import {DOMAttributes, Key, KeyboardDelegate, KeyboardEvents} from "@react-types/shared";
import {filterDOMProps, mergeProps} from "@react-aria/utils";
import {RefObject} from "react";
import {RefObject, KeyboardEvent as ReactKeyboardEvent} from "react";
import {TreeState} from "@react-stately/tree";
import {useSelectableList} from "@react-aria/selection";

Expand Down Expand Up @@ -46,7 +46,6 @@ export function useMenu<T>(
console.warn("An aria-label or aria-labelledby prop is required for accessibility.");
}

// @ts-ignore
let domProps = filterDOMProps(props, {labelable: true});
let {listProps} = useSelectableList({
...otherProps,
Expand All @@ -70,12 +69,12 @@ export function useMenu<T>(
{
role: "menu",
...listProps,
// @ts-ignore
onKeyDown: (e) => {
onKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => {
// don't clear the menu selected keys if the user is presses escape since escape closes the menu
if (e.key !== "Escape") {
// @ts-ignore
listProps.onKeyDown(e);
if (event.key !== "Escape") {
if (listProps.onKeyDown) {
listProps.onKeyDown(event);
}
}
},
},
Expand Down

0 comments on commit 54990e4

Please sign in to comment.