Skip to content

Commit

Permalink
fix(comp:alert): cannot change pagination.pageindex through button (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzaijiang committed Sep 1, 2022
1 parent 18f8795 commit 1669639
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
13 changes: 13 additions & 0 deletions packages/components/alert/__tests__/alert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,18 @@ describe('Alert', () => {

await wrapper.findAll('button')[0].trigger('click')
expect(wrapper.find('.ix-alert-content').text()).toBe('message1')

const onChange = vi.fn()

await wrapper.setProps({
pagination: {
pageIndex: 2,
onChange,
},
})
expect(wrapper.find('.ix-alert-content').text()).toBe('message2')

await wrapper.findAll('button')[0].trigger('click')
expect(onChange).toBeCalledWith(1)
})
})
21 changes: 16 additions & 5 deletions packages/components/alert/src/Alert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/

import { Transition, computed, defineComponent, normalizeClass, watchEffect } from 'vue'
import { Transition, computed, defineComponent, normalizeClass, watch } from 'vue'

import { isNil, isObject } from 'lodash-es'

Expand Down Expand Up @@ -40,11 +40,22 @@ export default defineComponent({
setPageIndex(index)
}

watchEffect(() => {
watch(
() => props.pagination,
pagination => {
if (isObject(pagination) && !isNil(pagination.pageIndex)) {
setPageIndex(pagination.pageIndex)
}
},
{
deep: true,
immediate: true,
},
)

watch(pageIndex, index => {
const { pagination } = props
if (isObject(pagination) && !isNil(pagination.pageIndex)) {
setPageIndex(pagination.pageIndex)
}
isObject(pagination) && callEmit(pagination.onChange, index)
})

const classes = computed(() => {
Expand Down

0 comments on commit 1669639

Please sign in to comment.