Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((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 = (
<button type="button" onClick={onClose} aria-label="Close" className={`${prefixCls}-close`}>
{closeIcon || <span className={`${prefixCls}-close-x`} />}
<button type="button" onClick={onClose} title={title} aria-label={ariaLabel ?? "Close"} className={`${prefixCls}-close`}>
{icon || <span className={`${prefixCls}-close-x`} />}
</button>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/IDialogPropTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<Dialog
visible
Expand Down Expand Up @@ -85,6 +85,23 @@ describe('dialog', () => {
expect(wrapper.find('.rc-dialog-mask').length).toBeTruthy();
});

it('closable props', () => {
const onClose = jest.fn();
const wrapper = mount(<Dialog closable={{ icon: "test", ariaLabel: "ariaLabelTest", title: "closableTitle" }} onClose={onClose} visible />);
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(<Dialog closeIcon="test" onClose={onClose} visible />);
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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(
<Dialog
visible
Expand Down