Browse Source

Accessibility of Alert close button

replace the <span> with <button> and style it accordingly #18736
pull/18791/head
MrHeer 5 years ago
committed by 偏右
parent
commit
bf5140b825
  1. 30
      components/alert/__tests__/__snapshots__/demo.test.js.snap
  2. 10
      components/alert/index.tsx
  3. 7
      components/alert/style/index.less

30
components/alert/__tests__/__snapshots__/demo.test.js.snap

@ -66,10 +66,10 @@ exports[`renders ./components/alert/demo/banner.md correctly 1`] = `
<span
class="ant-alert-description"
/>
<span
<button
class="ant-alert-close-icon"
role="button"
tabindex="0"
type="button"
>
<i
aria-label="icon: close"
@ -90,7 +90,7 @@ exports[`renders ./components/alert/demo/banner.md correctly 1`] = `
/>
</svg>
</i>
</span>
</button>
</div>
<br />
<div
@ -172,10 +172,10 @@ exports[`renders ./components/alert/demo/closable.md correctly 1`] = `
<span
class="ant-alert-description"
/>
<span
<button
class="ant-alert-close-icon"
role="button"
tabindex="0"
type="button"
>
<i
aria-label="icon: close"
@ -196,7 +196,7 @@ exports[`renders ./components/alert/demo/closable.md correctly 1`] = `
/>
</svg>
</i>
</span>
</button>
</div>
<div
class="ant-alert ant-alert-error ant-alert-with-description ant-alert-no-icon ant-alert-closable"
@ -212,10 +212,10 @@ exports[`renders ./components/alert/demo/closable.md correctly 1`] = `
>
Error Description Error Description Error Description Error Description Error Description Error Description
</span>
<span
<button
class="ant-alert-close-icon"
role="button"
tabindex="0"
type="button"
>
<i
aria-label="icon: close"
@ -236,7 +236,7 @@ exports[`renders ./components/alert/demo/closable.md correctly 1`] = `
/>
</svg>
</i>
</span>
</button>
</div>
</div>
`;
@ -254,17 +254,17 @@ exports[`renders ./components/alert/demo/close-text.md correctly 1`] = `
<span
class="ant-alert-description"
/>
<span
<button
class="ant-alert-close-icon"
role="button"
tabindex="0"
type="button"
>
<span
class="ant-alert-close-text"
>
Close Now
</span>
</span>
</button>
</div>
`;
@ -910,10 +910,10 @@ exports[`renders ./components/alert/demo/smooth-closed.md correctly 1`] = `
<span
class="ant-alert-description"
/>
<span
<button
class="ant-alert-close-icon"
role="button"
tabindex="0"
type="button"
>
<i
aria-label="icon: close"
@ -934,7 +934,7 @@ exports[`renders ./components/alert/demo/smooth-closed.md correctly 1`] = `
/>
</svg>
</i>
</span>
</button>
</div>
<p>
placeholder text here

10
components/alert/index.tsx

@ -23,7 +23,7 @@ export interface AlertProps {
/** Additional content of Alert */
description?: React.ReactNode;
/** Callback when close Alert */
onClose?: React.MouseEventHandler<HTMLAnchorElement>;
onClose?: React.MouseEventHandler<HTMLButtonElement>;
/** Trigger when animation ending of Alert */
afterClose?: () => void;
/** Whether to show icon */
@ -57,7 +57,7 @@ export default class Alert extends React.Component<AlertProps, AlertState> {
};
}
handleClose = (e: React.MouseEvent<HTMLAnchorElement>) => {
handleClose = (e: React.MouseEvent<HTMLButtonElement>) => {
e.preventDefault();
const dom = ReactDOM.findDOMNode(this) as HTMLElement;
dom.style.height = `${dom.offsetHeight}px`;
@ -143,8 +143,8 @@ export default class Alert extends React.Component<AlertProps, AlertState> {
);
const closeIcon = closable ? (
<span
role="button"
<button
type="button"
onClick={this.handleClose}
className={`${prefixCls}-close-icon`}
tabIndex={0}
@ -154,7 +154,7 @@ export default class Alert extends React.Component<AlertProps, AlertState> {
) : (
<Icon type="close" />
)}
</span>
</button>
) : null;
const dataOrAriaProps = getDataOrAriaProps(this.props);

7
components/alert/style/index.less

@ -74,8 +74,15 @@
overflow: hidden;
font-size: @font-size-sm;
line-height: 22px;
border: none;
background-color: transparent;
cursor: pointer;
&:focus {
outline-style: dotted;
outline-width: thin;
}
.@{iconfont-css-prefix}-close {
color: @alert-close-color;
transition: color 0.3s;

Loading…
Cancel
Save