Skip to content

Commit

Permalink
feat: Dialog support aria-* in closable
Browse files Browse the repository at this point in the history
  • Loading branch information
kiner-tang committed Feb 28, 2024
1 parent 7a3bb93 commit 4b418fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions src/Dialog/Content/Panel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import classNames from 'classnames';
import { useComposeRef } from 'rc-util/lib/ref';
import React, { useRef } from 'react';
import React, { useMemo, useRef } from 'react';
import { RefContext } from '../../context';
import type { IDialogPropTypes } from '../../IDialogPropTypes';
import MemoChildren from './MemoChildren';
import pickAttrs from 'rc-util/lib/pickAttrs';

const sentinelStyle = { width: 0, height: 0, overflow: 'hidden', outline: 'none' };
const entityStyle = { outline: 'none' };
Expand Down Expand Up @@ -95,12 +96,22 @@ const Panel = React.forwardRef<ContentRef, PanelProps>((props, ref) => {
</div>
);
}

const ariaProps = typeof closable === "object" ? pickAttrs(closable, true) : {};
const mergedClosableIcon = useMemo(() => {
if (typeof closable === "object" && closable.closeIcon) {
return closable.closeIcon;

Check warning on line 102 in src/Dialog/Content/Panel.tsx

View check run for this annotation

Codecov / codecov/patch

src/Dialog/Content/Panel.tsx#L102

Added line #L102 was not covered by tests
}
if (closable) {
return closeIcon ?? <span className={`${prefixCls}-close-x`} />;
}
return null;

Check warning on line 107 in src/Dialog/Content/Panel.tsx

View check run for this annotation

Codecov / codecov/patch

src/Dialog/Content/Panel.tsx#L107

Added line #L107 was not covered by tests
}, [closable, closeIcon]);

let closer: React.ReactNode;
if (closable) {
closer = (
<button type="button" onClick={onClose} aria-label="Close" className={`${prefixCls}-close`}>
{closeIcon || <span className={`${prefixCls}-close-x`} />}
<button type="button" onClick={onClose} aria-label="Close" {...ariaProps} className={`${prefixCls}-close`}>
{mergedClosableIcon}
</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 | ({ closeIcon?: React.ReactNode } & React.AriaAttributes);
maskClosable?: boolean;
visible?: boolean;
destroyOnClose?: boolean;
Expand Down

0 comments on commit 4b418fd

Please sign in to comment.