Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const Panel = React.forwardRef<PanelRef, PanelProps>((props, ref) => {
return {};
}, [closable, closeIcon, prefixCls]);

const ariaProps = pickAttrs(closableObj, true);
const ariaProps = pickAttrs(closableObj, { aria: true, data: true });
const closeBtnIsDisabled = typeof closable === 'object' && closable.disabled;

const closerNode = closable ? (
Expand Down
4 changes: 3 additions & 1 deletion src/IDialogPropTypes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { GetContainer } from '@rc-component/util';
import type { CSSProperties, ReactNode, SyntheticEvent } from 'react';

export type SemanticName = 'header' | 'body' | 'footer' | 'container' | 'title' | 'wrapper' | 'mask' | 'close';
export type SemanticName =
'header' | 'body' | 'footer' | 'container' | 'title' | 'wrapper' | 'mask' | 'close';

export type ModalClassNames = Partial<Record<SemanticName, string>>;

export type ModalStyles = Partial<Record<SemanticName, CSSProperties>>;

export type ClosableType = {
[key: `data-${string}`]: unknown;
closeIcon?: React.ReactNode;
disabled?: boolean;
afterClose?: () => any;
Expand Down
19 changes: 16 additions & 3 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -705,27 +705,38 @@ describe('dialog', () => {
spy.mockRestore();
});

it('support aria-* in closable', () => {
it('support aria-* and data-* in closable', () => {
const onClose = jest.fn();
render(
const onClick = jest.fn();
const { getByTestId } = render(
<Dialog
closable={{
...{ role: 'button', title: 'Not a close button attribute', onClick },
closeIcon: 'test',
'aria-label': 'test aria-label',
'data-testid': 'dialog-close',
'data-count': 0,
}}
visible
onClose={onClose}
/>,
);
jest.runAllTimers();

const btn = document.querySelector('.rc-dialog-close');
const btn = getByTestId('dialog-close');
expect(btn).toBe(document.querySelector('button.rc-dialog-close'));
expect(btn.textContent).toBe('test');
expect(btn.getAttribute('aria-label')).toBe('test aria-label');
expect(btn).toHaveAttribute('role', 'button');
expect(btn).toHaveAttribute('data-count', '0');
expect(btn).not.toHaveAttribute('title');
expect(btn).not.toHaveAttribute('closeIcon');
fireEvent.click(btn);

jest.runAllTimers();
expect(onClose).toHaveBeenCalledTimes(1);
expect(onClose).toHaveBeenCalledWith(expect.objectContaining({ type: 'click' }));
expect(onClick).not.toHaveBeenCalled();
});

it('support disable button in closable', () => {
Expand All @@ -735,6 +746,7 @@ describe('dialog', () => {
closable={{
closeIcon: 'test',
disabled: true,
'data-testid': 'disabled-dialog-close',
}}
visible
onClose={onClose}
Expand All @@ -744,6 +756,7 @@ describe('dialog', () => {

const btn = document.querySelector<HTMLButtonElement>('.rc-dialog-close');
expect(btn.disabled).toBeTruthy();
expect(btn).toHaveAttribute('data-testid', 'disabled-dialog-close');
fireEvent.click(btn);

jest.runAllTimers();
Expand Down
Loading