fix(collapse): 修复collapse未深度监听导致Pc端tiny-collapse activeNames直接push无法响应的bug (#512)

This commit is contained in:
Kif 2023-09-27 10:37:33 +08:00 committed by GitHub
parent 7f0f027765
commit 0036fcb203
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -33,7 +33,7 @@ export const renderless = (props, { reactive, watch }, { parent, emit, constants
(value) => {
state.activeNames = value || value === 0 ? [].concat(value) : []
},
{ immediate: true }
{ immediate: true, deep: true }
)
parent.$on(eventName, api.handleItemClick)

View File

@ -2,17 +2,22 @@ import { mountPcMode } from '@opentiny-internal/vue-test-utils'
import { describe, test, expect, vi } from 'vitest'
import Collapse from '@opentiny/vue-collapse'
import CollapseItem from '@opentiny/vue-collapse-item'
import { ref } from 'vue'
describe('PC Mode', () => {
const mount = mountPcMode
const handleChange = vi.fn()
const activeNames = ref(['1'])
const wrapper = mount(() => (
<Collapse modelValue="1" onChange={handleChange}>
<Collapse modelValue={activeNames.value} onChange={handleChange}>
<CollapseItem title="一致性 Consistency" name="1">
<div>1</div>
<div>2</div>
</CollapseItem>
<CollapseItem title="反馈 Feedback" name="2">
<div>3</div>
<div>4</div>
</CollapseItem>
</Collapse>
))
@ -34,4 +39,11 @@ describe('PC Mode', () => {
await wrapper.find('.tiny-collapse-item__header').trigger('click')
expect(handleChange).toBeCalled()
})
})
// ref test
test('ref test', async () => {
activeNames.value.push('2')
await wrapper.vm.$nextTick()
expect(wrapper.find('.is-active').exists()).toBeTruthy()
})
})