Skip to content

Commit

Permalink
chore(liveness): add a11y error label to alert icon (#4888)
Browse files Browse the repository at this point in the history
* adding error label to alert icon

* Create rich-keys-retire.md

* updating props and snapshot

* adding display text for error

* defining label outside of switch statement

* updating props

* update props
  • Loading branch information
esauerbo authored Jan 9, 2024
1 parent 067e2b1 commit da41cca
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .changeset/rich-keys-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@aws-amplify/ui-react-liveness": patch
"@aws-amplify/ui-react": patch
---

chore(liveness): adding a11y error label to alert icon in timeout message
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type StreamDisplayText = {
};

export const defaultErrorDisplayText = {
errorLabelText: 'Error',
timeoutHeaderText: 'Time out',
timeoutMessageText:
"Face didn't fit inside oval in time limit. Try again and completely fill the oval with face in it.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const renderToastErrorModal = (props: {
const { error: errorState, displayText } = props;

const {
errorLabelText,
timeoutHeaderText,
timeoutMessageText,
faceDistanceHeaderText,
Expand Down Expand Up @@ -68,7 +69,7 @@ const renderToastErrorModal = (props: {
return (
<>
<Flex className={LivenessClassNames.ErrorModal}>
<AlertIcon ariaHidden variation="error" />
<AlertIcon ariaLabel={errorLabelText} role="img" variation="error" />
<Text
className={LivenessClassNames.ErrorModalHeading}
id="amplify-liveness-error-heading"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function getDisplayText(
cancelLivenessCheckText,
clientHeaderText,
clientMessageText,
errorLabelText,
hintCanNotIdentifyText,
hintCenterFaceText,
hintConnectingText,
Expand Down Expand Up @@ -131,6 +132,7 @@ export function getDisplayText(
};

const errorDisplayText: Required<ErrorDisplayText> = {
errorLabelText,
timeoutHeaderText,
timeoutMessageText,
faceDistanceHeaderText,
Expand Down
34 changes: 28 additions & 6 deletions packages/react/src/primitives/Alert/AlertIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';

import { ComponentClassName } from '@aws-amplify/ui';
import { AlertVariations } from '../types';
import { AlertVariations, ViewProps } from '../types';

import {
IconInfo,
Expand All @@ -11,7 +11,7 @@ import {
useIcons,
} from '../Icon';

interface AlertIconProps {
interface AlertIconProps extends Pick<ViewProps, 'role' | 'ariaLabel'> {
variation?: AlertVariations;
ariaHidden?: boolean;
}
Expand All @@ -22,21 +22,43 @@ interface AlertIconProps {
export const AlertIcon = ({
variation,
ariaHidden,
ariaLabel,
role,
}: AlertIconProps): JSX.Element | null => {
const icons = useIcons('alert');
let icon;
switch (variation) {
case 'info':
icon = icons?.info ?? <IconInfo aria-hidden={ariaHidden} />;
icon = icons?.info ?? (
<IconInfo aria-hidden={ariaHidden} aria-label={ariaLabel} role={role} />
);
break;
case 'error':
icon = icons?.error ?? <IconError aria-hidden={ariaHidden} />;
icon = icons?.error ?? (
<IconError
aria-hidden={ariaHidden}
aria-label={ariaLabel}
role={role}
/>
);
break;
case 'warning':
icon = icons?.warning ?? <IconWarning aria-hidden={ariaHidden} />;
icon = icons?.warning ?? (
<IconWarning
aria-hidden={ariaHidden}
aria-label={ariaLabel}
role={role}
/>
);
break;
case 'success':
icon = icons?.success ?? <IconCheckCircle aria-hidden={ariaHidden} />;
icon = icons?.success ?? (
<IconCheckCircle
aria-hidden={ariaHidden}
aria-label={ariaLabel}
role={role}
/>
);
break;
}

Expand Down

0 comments on commit da41cca

Please sign in to comment.