Skip to content

Commit

Permalink
fix(Menu): subContent flickers, item disabled was selected (#648)
Browse files Browse the repository at this point in the history
  • Loading branch information
zernonia committed Feb 1, 2024
1 parent 95ef82a commit a0b07de
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { Icon } from '@iconify/vue'
import { ref, watch } from 'vue'
import { ref } from 'vue'
import {
DropdownMenuArrow,
DropdownMenuCheckboxItem,
Expand Down Expand Up @@ -33,12 +33,6 @@ function handleCheck(ev: any) {
// checkboxOne.value = ev;
console.log(ev)
}
const el = ref<InstanceType<typeof DropdownMenuItem>>()
watch(el, () => {
console.log(el.value)
}, { immediate: true, deep: true })
</script>

<template>
Expand All @@ -58,7 +52,6 @@ watch(el, () => {
class="min-w-[220px] bg-white rounded-md p-[5px] shadow-[0px_10px_38px_-10px_rgba(22,_23,_24,_0.35),_0px_10px_20px_-15px_rgba(22,_23,_24,_0.2)] will-change-[opacity,transform] data-[side=top]:animate-slideDownAndFade data-[side=right]:animate-slideLeftAndFade data-[side=bottom]:animate-slideUpAndFade data-[side=left]:animate-slideRightAndFade"
>
<DropdownMenuItem
ref="el"
value="New Tab"
class="group text-[13px] leading-none text-violet11 rounded-[3px] flex items-center h-[25px] px-[5px] relative pl-[25px] select-none outline-none data-[disabled]:text-mauve8 data-[disabled]:pointer-events-none data-[highlighted]:bg-violet9 data-[highlighted]:text-violet1"
@click="handleClick"
Expand Down
1 change: 1 addition & 0 deletions packages/radix-vue/src/Menu/MenuContentImpl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ function handleKeyDown(event: KeyboardEvent) {
arrowKeyOptions: 'vertical',
dir: rootContext?.dir.value,
focus: true,
attributeName: '[data-radix-vue-collection-item]:not([data-disabled])',
},
)
if (el)
Expand Down
7 changes: 4 additions & 3 deletions packages/radix-vue/src/Menu/MenuSubTrigger.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface MenuSubTriggerProps extends MenuItemImplProps {}
</script>

<script setup lang="ts">
import { nextTick, onUnmounted, ref } from 'vue'
import { type ComponentPublicInstance, nextTick, onUnmounted, ref } from 'vue'
import MenuItemImpl from './MenuItemImpl.vue'
import { injectMenuContext, injectMenuRootContext } from './MenuRoot.vue'
import { injectMenuSubContext } from './MenuSub.vue'
Expand Down Expand Up @@ -117,9 +117,10 @@ async function handleKeyDown(event: KeyboardEvent) {
v-bind="props"
:id="subContext.triggerId"
:ref="
(vnode) => {
(vnode: ComponentPublicInstance) => {
// @ts-ignore
subContext?.onTriggerChange(vnode?.el);
subContext?.onTriggerChange(vnode?.$el);
return undefined
}
"
aria-haspopup="menu"
Expand Down
4 changes: 2 additions & 2 deletions packages/radix-vue/src/shared/useArrowNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export function useArrowNavigation(

const {
arrowKeyOptions = 'both',
attributeName = 'data-radix-vue-collection-item',
attributeName = '[data-radix-vue-collection-item]',
itemsArray = [],
loop = true,
dir = 'ltr',
Expand Down Expand Up @@ -112,7 +112,7 @@ export function useArrowNavigation(
return null

const allCollectionItems: HTMLElement[] = parentElement
? Array.from(parentElement.querySelectorAll(`[${attributeName}]`))
? Array.from(parentElement.querySelectorAll(attributeName))
: itemsArray

if (!allCollectionItems.length)
Expand Down
2 changes: 1 addition & 1 deletion packages/radix-vue/src/shared/useCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function useCollection(key?: string, name = ITEM_DATA_ATTR) {
return (items.value = [])

return (items.value = Array.from(
sourceEl.querySelectorAll(`[${name}]:not([data-disabled=true])`),
sourceEl.querySelectorAll(`[${name}]:not([data-disabled])`),
) as HTMLElement[])
}

Expand Down

0 comments on commit a0b07de

Please sign in to comment.