diff --git a/src/Dialog/Content/Panel.tsx b/src/Dialog/Content/Panel.tsx index 08256843..e59a4a4a 100644 --- a/src/Dialog/Content/Panel.tsx +++ b/src/Dialog/Content/Panel.tsx @@ -110,7 +110,7 @@ const Panel = React.forwardRef((props, ref) => { return {}; }, [closable, closeIcon, prefixCls]); - const ariaProps = pickAttrs(closableObj, true); + const closableAriaProps = pickAttrs(closableObj, true); const closeBtnIsDisabled = typeof closable === 'object' && closable.disabled; const closerNode = closable ? ( @@ -118,7 +118,7 @@ const Panel = React.forwardRef((props, ref) => { type="button" onClick={onClose} aria-label="Close" - {...ariaProps} + {...closableAriaProps} className={clsx(`${prefixCls}-close`, modalClassNames?.close)} disabled={closeBtnIsDisabled} style={modalStyles?.close} @@ -145,11 +145,14 @@ const Panel = React.forwardRef((props, ref) => { ); + const ariaProps = pickAttrs(props, { aria: true }); + return (
>; @@ -14,6 +15,7 @@ export type ClosableType = { }; export type IDialogPropTypes = { + role?: AriaRole; className?: string; keyboard?: boolean; style?: CSSProperties; @@ -64,4 +66,4 @@ export type IDialogPropTypes = { // Refs panelRef?: React.Ref; -}; +} & AriaAttributes; diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index dcb33153..0cf437e3 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -765,4 +765,21 @@ describe('dialog', () => { expect(document.querySelector('.rc-dialog')).toBeTruthy(); expect(document.querySelector('.rc-dialog-close')).toBeFalsy(); }); + + it('support custom role and aria attributes', () => { + render( + , + ); + jest.runAllTimers(); + + const dialog = document.querySelector('.rc-dialog'); + expect(dialog.getAttribute('role')).toBe('alertdialog'); + expect(dialog.getAttribute('aria-describedby')).toBe('custom-description'); + expect(dialog.getAttribute('aria-label')).toBe('custom-label'); + }); });