Skip to content

Commit

Permalink
fix(comp:ixmenu): fix error when initialize settings expandKeys (#637)
Browse files Browse the repository at this point in the history
fix #636
  • Loading branch information
东木 committed Dec 21, 2021
1 parent b9d1d19 commit 131d95b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 4 additions & 2 deletions packages/components/menu/__tests__/menu.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ describe('Menu', () => {

test('v-model:expandedKeys work', async () => {
const onUpdateExpandedKeys = jest.fn()
const wrapper = MenuMount({ props: { expandedKeys: ['sub1'], 'onUpdate:expandedKeys': onUpdateExpandedKeys } })
const wrapper = MenuMount({
props: { expandedKeys: ['sub1'], 'onUpdate:expandedKeys': onUpdateExpandedKeys, mode: 'inline' },
})

const subs = wrapper.findAllComponents(MenuSub)
expect(subs.length).toBe(4)
Expand All @@ -101,7 +103,7 @@ describe('Menu', () => {
expect(subs[3].classes()).toContain('ix-menu-sub-expanded')

await wrapper.setProps({ expandedKeys: [] })
await subs[0].find('.ix-menu-sub-title').trigger('mouseenter')
await subs[0].find('.ix-menu-sub-title').trigger('click')
await wait(105)

expect(onUpdateExpandedKeys).toBeCalledWith(['sub1'])
Expand Down
10 changes: 8 additions & 2 deletions packages/components/menu/src/children/menu-sub/MenuSub.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,16 @@ function useExpanded(
handleExpand: (key: VKey, expanded: boolean) => void,
mode: ComputedRef<'vertical' | 'horizontal' | 'inline'>,
) {
const isExpanded = computed(() => expandedKeys.value.includes(key))
const isHover = ref(false)
const isExpanded = computed(() => {
// https://github.com/IDuxFE/idux/issues/636
if (mode.value === 'inline') {
return expandedKeys.value.includes(key)
}
return isHover.value && expandedKeys.value.includes(key)
})
const changeExpanded = (expanded: boolean) => handleExpand(key, expanded)
const childExpanded = computed(() => getState(props.children, expandedKeys.value))
const isHover = ref(false)
const handleMouseEvent = debounce((value: boolean) => (isHover.value = value), 100)
watch([mode, childExpanded, isHover], ([currMode, currChildExpanded, currIsHover]) => {
if (currMode !== 'inline') {
Expand Down

0 comments on commit 131d95b

Please sign in to comment.