-
Notifications
You must be signed in to change notification settings - Fork 873
[EuiProgress][A11y] Announce determinate progress update to screen readers #8839
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
Changes from all commits
a623f3f
ef4b7a1
c18e230
fa71211
ff28b83
e8dd42b
d794c0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| **Accessibility** | ||
|
|
||
| - Improved the experience of `EuiProgress` by ensuring that determinate updates are read out immediately to screen readers | ||
|
|
|
mgadewoll marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,10 @@ import React, { | |
| ProgressHTMLAttributes, | ||
| ReactNode, | ||
| CSSProperties, | ||
| useState, | ||
| useRef, | ||
| useEffect, | ||
| MutableRefObject, | ||
| } from 'react'; | ||
| import classNames from 'classnames'; | ||
| import { EuiI18n } from '../i18n'; | ||
|
|
@@ -20,6 +24,7 @@ import { CommonProps, ExclusiveUnion } from '../common'; | |
| import { isNil } from '../../services/predicate'; | ||
|
|
||
| import { useEuiTheme, makeHighContrastColor } from '../../services'; | ||
| import { EuiScreenReaderOnly } from '../accessibility'; | ||
| import { | ||
| euiProgressStyles, | ||
| euiProgressDataStyles, | ||
|
|
@@ -67,9 +72,15 @@ type Indeterminate = EuiProgressProps & HTMLAttributes<HTMLDivElement>; | |
|
|
||
| type Determinate = EuiProgressProps & | ||
| Omit<ProgressHTMLAttributes<HTMLProgressElement>, 'max'> & { | ||
| /** | ||
| * When set, creates determinate progress with a value/max ratio | ||
| */ | ||
| max?: number; | ||
| /* | ||
| * If true, will render the percentage, otherwise pass a custom node | ||
| /** | ||
| * Displays custom text or percentage | ||
| * Pass `true` to display the percentage value | ||
| * Pass a ReactNode for custom text | ||
| * @default false | ||
| */ | ||
| valueText?: boolean | ReactNode; | ||
| label?: ReactNode; | ||
|
|
@@ -93,6 +104,11 @@ export const EuiProgress: FunctionComponent< | |
| labelProps, | ||
| ...rest | ||
| }) => { | ||
| const valueTextRef: MutableRefObject<HTMLSpanElement | null> = useRef(null); | ||
| const labelRef: MutableRefObject<HTMLSpanElement | null> = useRef(null); | ||
| const [innerValueText, setInnerValueText] = useState<string | undefined>(); | ||
| const [labelText, setLabelText] = useState<string | undefined>(); | ||
|
|
||
| const determinate = !isNil(max); | ||
| const isNamedColor = COLORS.includes(color as EuiProgressColor); | ||
|
|
||
|
|
@@ -149,6 +165,11 @@ export const EuiProgress: FunctionComponent< | |
| valueRender = valueText; | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| setInnerValueText(valueTextRef.current?.textContent ?? ''); | ||
| setLabelText(labelRef.current?.textContent ?? ''); | ||
| }, [label, valueRender, value]); | ||
|
|
||
| // Because of a Firefox animation issue, indeterminate progress needs to not use <progress />. | ||
| // See https://css-tricks.com/html5-progress-element/ | ||
|
|
||
|
|
@@ -162,10 +183,14 @@ export const EuiProgress: FunctionComponent< | |
| {(ref, innerText) => ( | ||
| <span | ||
| title={innerText} | ||
| ref={ref} | ||
| ref={(node) => { | ||
| labelRef.current = node; | ||
| ref?.(node); | ||
| }} | ||
| {...labelProps} | ||
| className={labelClasses} | ||
| css={labelCssStyles} | ||
| aria-hidden="true" | ||
| > | ||
| {label} | ||
| </span> | ||
|
|
@@ -177,10 +202,14 @@ export const EuiProgress: FunctionComponent< | |
| {(ref, innerText) => ( | ||
| <span | ||
| title={innerText} | ||
| ref={ref} | ||
| ref={(node) => { | ||
| valueTextRef.current = node; | ||
| ref?.(node); | ||
| }} | ||
| style={customTextColorStyles} | ||
| css={valueTextCssStyles} | ||
| className="euiProgress__valueText" | ||
| aria-hidden="true" | ||
| > | ||
| {valueRender} | ||
| </span> | ||
|
|
@@ -189,13 +218,22 @@ export const EuiProgress: FunctionComponent< | |
| )} | ||
| </div> | ||
| ) : undefined} | ||
| <EuiScreenReaderOnly> | ||
| <div aria-live="polite" aria-atomic="true"> | ||
| <span> | ||
| {label && `${label} `} | ||
| {valueRender || value} | ||
| </span> | ||
| </div> | ||
| </EuiScreenReaderOnly> | ||
|
mgadewoll marked this conversation as resolved.
|
||
| <progress | ||
| css={cssStyles} | ||
| className={classes} | ||
| style={customColorStyles} | ||
| max={max} | ||
| value={value} | ||
| aria-hidden={label && valueText ? true : false} | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ℹ️ Removing The previous idea here was that the progress bar is not needed as it's a graphical representation of the
|
||
| aria-valuetext={innerValueText || undefined} | ||
| aria-label={labelText || undefined} | ||
| {...(rest as ProgressHTMLAttributes<HTMLProgressElement>)} | ||
| /> | ||
| </> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.