Skip to content

Commit 403952f

Browse files
authored
fix(drawer): report sizes in resize callbacks (#84)
Sync react-component/drawer#628.
1 parent 4c543db commit 403952f

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

packages/drawer/src/DrawerPopup.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ export interface DrawerPopupProps extends DrawerPanelEvents {
7373
| boolean
7474
| {
7575
onResize?: (size: number) => void
76-
onResizeStart?: () => void
77-
onResizeEnd?: () => void
76+
onResizeStart?: (size: number) => void
77+
onResizeEnd?: (size: number) => void
7878
}
7979

8080
}
@@ -215,8 +215,8 @@ const DrawerPopup = defineComponent<DrawerPopupProps>(
215215
containerRef: wrapperRef,
216216
currentSize: mergedSize,
217217
onResize: onInternalResize,
218-
onResizeStart: () => resizeConfig?.value?.onResizeStart?.(),
219-
onResizeEnd: () => resizeConfig?.value?.onResizeEnd?.(),
218+
onResizeStart: size => resizeConfig?.value?.onResizeStart?.(size),
219+
onResizeEnd: size => resizeConfig?.value?.onResizeEnd?.(size),
220220
})
221221
return () => {
222222
const {

packages/drawer/tests/index.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,41 @@ describe('vc-drawer', () => {
4444
await nextTick()
4545
})
4646

47+
it('reports drawer sizes when resize starts and ends', async () => {
48+
const onResizeStart = vi.fn()
49+
const onResizeEnd = vi.fn()
50+
const wrapper = mount(Drawer, {
51+
props: {
52+
open: true,
53+
getContainer: false,
54+
placement: 'right',
55+
defaultSize: 320,
56+
resizable: {
57+
onResizeStart,
58+
onResizeEnd,
59+
},
60+
...motionProps,
61+
},
62+
})
63+
64+
await nextTick()
65+
const contentWrapper = wrapper.find('.vc-drawer-content-wrapper').element as HTMLElement
66+
contentWrapper.getBoundingClientRect = vi.fn(() => ({
67+
width: 360,
68+
height: 0,
69+
} as DOMRect))
70+
71+
await wrapper.find('.vc-drawer-resizable-dragger').trigger('mousedown', { clientX: 100 })
72+
await nextTick()
73+
document.dispatchEvent(new MouseEvent('mouseup'))
74+
75+
expect(onResizeStart).toHaveBeenCalledWith(320)
76+
expect(onResizeEnd).toHaveBeenCalledWith(360)
77+
78+
wrapper.unmount()
79+
await nextTick()
80+
})
81+
4782
it('closes on Escape when getContainer is false', async () => {
4883
const onClose = vi.fn()
4984
const wrapper = mount(Drawer, {

0 commit comments

Comments
 (0)