Skip to content

Improve screen reader support for credit card error messages #103846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
11 changes: 10 additions & 1 deletion client/components/notice/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ interface NoticeProps {
theme?: 'light' | 'dark';
text?: ReactNode;
children?: ReactNode;
ariaLive?: 'off' | 'polite' | 'assertive';
role?: 'status' | 'alert' | 'log' | 'marquee' | 'timer';
}

function getIcon( status: NoticeStatus | undefined ): string {
Expand Down Expand Up @@ -76,6 +78,8 @@ export default function Notice( {
status,
text,
theme = 'dark',
ariaLive,
role = 'status',
}: NoticeProps ) {
const translate = useTranslate();

Expand Down Expand Up @@ -118,7 +122,12 @@ export default function Notice( {
}

return (
<div className={ classes } role="status" aria-label={ translate( 'Notice' ) }>
<div
className={ classes }
role={ role || 'status' }
aria-label={ translate( 'Notice' ) }
aria-live={ ariaLive }
>
<span className="calypso-notice__icon-wrapper">
{ iconNeedsDrop && <span className="calypso-notice__icon-wrapper-drop" /> }
{ renderedIcon }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function CreditCardPayButton( {
useEffect( () => {
if ( displayFieldsError ) {
document.body.scrollTop = document.documentElement.scrollTop = 0;
reduxDispatch( errorNotice( displayFieldsError ) );
reduxDispatch( errorNotice( displayFieldsError, { ariaLive: 'assertive', role: 'alert' } ) );
setDisplayFieldsError( '' );
}
}, [ displayFieldsError, reduxDispatch ] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const StripeFieldWrapper = styled.span< { hasError?: boolean; isDisabled?
cursor: ${ ( props ) => props.isDisabled && 'default' };
`;

export const StripeErrorMessage = styled.span`
const StyledStripeErrorMessage = styled.div`
font-size: 14px;
margin-top: 8px;
font-style: italic;
Expand All @@ -70,6 +70,16 @@ export const StripeErrorMessage = styled.span`
font-weight: ${ ( props ) => props.theme.weights.normal };
`;

export const StripeErrorMessage = ( {
id,
children,
...props
}: React.HTMLAttributes< HTMLSpanElement > ) => (
<StyledStripeErrorMessage id={ id } aria-invalid="true" aria-live="assertive" { ...props }>
{ children }
</StyledStripeErrorMessage>
);

export const CreditCardFieldsWrapper = styled.div< { isLoaded?: boolean } >`
padding: 0 24px 24px 24px;
position: relative;
Expand Down
2 changes: 2 additions & 0 deletions client/state/notices/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface BaseNoticeOptions {
onClick?: () => void;
showDismiss?: boolean;
onDismissClick?: () => void;
ariaLive?: 'off' | 'polite' | 'assertive';
role?: string;
}

// Notice options as they're expected by the action creator
Expand Down