Skip to content

Commit

Permalink
fix(NavigationMenu): client-side nav was prevented by RouterLink (#1221)
Browse files Browse the repository at this point in the history
* fix(NavigationMenu): client-side nav was prevented by RouterLink

* chore: emit originalEvent
  • Loading branch information
zernonia authored Aug 13, 2024
1 parent 5bef21d commit 35886c6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions packages/radix-vue/src/NavigationMenu/NavigationMenuItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ function handleKeydown(ev: KeyboardEvent) {
i.parentElement?.hasAttribute('data-menu-item'),
)
// prevent triggering when the focus is on link
if (!itemsArray.includes(currentFocus))
return
const newSelectedElement = useArrowNavigation(ev, currentFocus, undefined, {
itemsArray,
loop: false,
Expand Down
20 changes: 12 additions & 8 deletions packages/radix-vue/src/NavigationMenu/NavigationMenuLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export type NavigationMenuLinkEmits = {
*
* Calling `event.preventDefault` in this handler will prevent the navigation menu from closing when selecting that link.
*/
select: [payload: MouseEvent]
select: [payload: CustomEvent<{ originalEvent: Event }>]
}
export interface NavigationMenuLinkProps extends PrimitiveProps {
/** Used to identify the link as the currently active page. */
Expand All @@ -17,23 +17,27 @@ export interface NavigationMenuLinkProps extends PrimitiveProps {
</script>

<script setup lang="ts">
import { nextTick } from 'vue'
import { Primitive } from '@/Primitive'
import { EVENT_ROOT_CONTENT_DISMISS } from './utils'
// const LINK_SELECT = "navigationMenu.linkSelect";
import { EVENT_ROOT_CONTENT_DISMISS, LINK_SELECT } from './utils'
const props = withDefaults(defineProps<NavigationMenuLinkProps>(), {
as: 'a',
})
const emits = defineEmits<NavigationMenuLinkEmits>()
useForwardExpose()
async function handleClick(ev: MouseEvent) {
emits('select', ev)
const linkSelectEvent = new CustomEvent(LINK_SELECT, {
bubbles: true,
cancelable: true,
detail: {
originalEvent: ev,
},
})
emits('select', linkSelectEvent)
await nextTick()
if (!ev.defaultPrevented && !ev.metaKey) {
if (!linkSelectEvent.defaultPrevented && !ev.metaKey) {
const rootContentDismissEvent = new CustomEvent(
EVENT_ROOT_CONTENT_DISMISS,
{
Expand Down
1 change: 1 addition & 0 deletions packages/radix-vue/src/NavigationMenu/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function makeContentId(baseId: string, value: string) {
return `${baseId}-content-${value}`
}

export const LINK_SELECT = 'navigationMenu.linkSelect'
export const EVENT_ROOT_CONTENT_DISMISS = 'navigationMenu.rootContentDismiss'

/**
Expand Down

0 comments on commit 35886c6

Please sign in to comment.