diff --git a/src/Dialog/Content/Panel.tsx b/src/Dialog/Content/Panel.tsx index 2aa492af..3fccb6cb 100644 --- a/src/Dialog/Content/Panel.tsx +++ b/src/Dialog/Content/Panel.tsx @@ -96,9 +96,18 @@ const Panel = React.forwardRef((props, ref) => { let closer: React.ReactNode; if (closable) { + let icon: React.ReactNode, ariaLabel: string, title: string; + if (typeof closable === 'object') { + icon = closable.icon; + ariaLabel = closable.ariaLabel; + title = closable.title; + } else { + icon = closeIcon; + } + closer = ( - ); } diff --git a/src/IDialogPropTypes.tsx b/src/IDialogPropTypes.tsx index ac64ac33..ba6697e3 100644 --- a/src/IDialogPropTypes.tsx +++ b/src/IDialogPropTypes.tsx @@ -28,7 +28,7 @@ export type IDialogPropTypes = { afterClose?: () => any; afterOpenChange?: (open: boolean) => void; onClose?: (e: SyntheticEvent) => any; - closable?: boolean; + closable?: boolean | { icon?: ReactNode, title?: string, ariaLabel?: string }; maskClosable?: boolean; visible?: boolean; destroyOnClose?: boolean; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 0eed6d5e..dfe431fb 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -37,7 +37,7 @@ describe('dialog', () => { }); it('add rootClassName should render correct', () => { - const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const spy = jest.spyOn(console, 'error').mockImplementation(() => { }); const wrapper = mount( { expect(wrapper.find('.rc-dialog-mask').length).toBeTruthy(); }); + it('closable props', () => { + const onClose = jest.fn(); + const wrapper = mount(); + jest.runAllTimers(); + wrapper.update(); + + const btn = wrapper.find('.rc-dialog-close'); + expect(btn.prop("aria-label") === "ariaLabelTest"); + expect(btn.prop("title") === "closableTitle"); + expect(btn.text()).toBe('test'); + btn.simulate('click'); + + jest.runAllTimers(); + wrapper.update(); + expect(onClose).toHaveBeenCalledTimes(1); + }); + it('click close', () => { const onClose = jest.fn(); const wrapper = mount(); @@ -579,7 +596,7 @@ describe('dialog', () => { expect(wrapper.find('.rc-dialog-footer').props().className).toContain('custom-footer'); expect(wrapper.find('.rc-dialog-mask').props().className).toContain('custom-mask'); expect(wrapper.find('.rc-dialog-content').props().className).toContain('custom-content'); - + }); it('should support styles', () => { @@ -612,7 +629,7 @@ describe('dialog', () => { expect(wrapper.find('.rc-dialog-content').props().style.background).toBe('orange'); }); it('should warning', () => { - const spy = jest.spyOn(console, 'error').mockImplementation(() => {}); + const spy = jest.spyOn(console, 'error').mockImplementation(() => { }); const wrapper = mount(