Skip to content

Commit

Permalink
fix(NavigationMenu): input not working in NavigationContent (#644)
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Jan 31, 2024
1 parent dc4e3e7 commit 912562a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,9 @@ function handleKeydown(ev: KeyboardEvent) {
ev,
document.activeElement as HTMLElement,
undefined,
{ itemsArray: candidates, loop: false },
{ itemsArray: candidates, loop: false, enableIgnoredElement: true },
)
newSelectedElement?.focus()
if (ev.key === 'Enter' || ev.key === 'Escape')
return
ev.preventDefault()
ev.stopPropagation()
}
function handleDismiss() {
Expand Down
11 changes: 10 additions & 1 deletion packages/radix-vue/src/shared/useArrowNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ interface ArrowNavigationOptions {
*/
preventScroll?: boolean

/**
* By default all currentElement would trigger navigation. If `true`, currentElement nodeName in the ignore list will return null
*
* @defaultValue false
*/
enableIgnoredElement?: boolean

/**
* Focus the element after navigation
*
Expand All @@ -55,6 +62,8 @@ interface ArrowNavigationOptions {
focus?: boolean
}

const ignoredElement = ['INPUT', 'TEXTAREA']

/**
* Allow arrow navigation for every html element with data-radix-vue-collection-item tag
*
Expand All @@ -70,7 +79,7 @@ export function useArrowNavigation(
parentElement: HTMLElement | undefined,
options: ArrowNavigationOptions = {},
): HTMLElement | null {
if (!currentElement)
if (!currentElement || (options.enableIgnoredElement && ignoredElement.includes(currentElement.nodeName)))
return null

const {
Expand Down

0 comments on commit 912562a

Please sign in to comment.