Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hooks): resolve type error in onKeyDown event handler #3064

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
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
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": patch
---

Fixed a type error in the onKeyDown event handler for the menu component
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
Loading