Skip to content

Commit

Permalink
fix(NavigationMenu): client-side nav was prevented by RouterLink
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Aug 12, 2024
1 parent 12af841 commit 690551a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 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: Event]
}
export interface NavigationMenuLinkProps extends PrimitiveProps {
/** Used to identify the link as the currently active page. */
Expand All @@ -19,7 +19,7 @@ export interface NavigationMenuLinkProps extends PrimitiveProps {
<script setup lang="ts">
import { nextTick } from 'vue'
import { Primitive } from '@/Primitive'
import { EVENT_ROOT_CONTENT_DISMISS } from './utils'
import { EVENT_ROOT_CONTENT_DISMISS, LINK_SELECT } from './utils'
// const LINK_SELECT = "navigationMenu.linkSelect";
Expand All @@ -30,10 +30,13 @@ const emits = defineEmits<NavigationMenuLinkEmits>()
useForwardExpose()
async function handleClick(ev: MouseEvent) {
emits('select', ev)
const linkSelectEvent = new CustomEvent(LINK_SELECT, {
bubbles: true,
cancelable: true,
})
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 690551a

Please sign in to comment.