Skip to content
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

[EuiRange]: Add conditional aria-valuetext when ticks prop is passed #7675

Merged
merged 20 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b6085ce
Added aria-valuetext logic to EuiRangeSlider.
1Copenut Apr 10, 2024
aab49b5
Added accessibleLabel type to EuiRangeTick, logic to build aria-value…
1Copenut Apr 10, 2024
a8517c8
Adding aria-valuenow logic for EuiRange.
1Copenut Apr 11, 2024
da14962
Adding unit test logic for aria-valuenow and aria-valuetext.
1Copenut Apr 11, 2024
5cc66a5
Updated EuiRange ticks doc with accessibleLabel.
1Copenut Apr 10, 2024
7c155dc
Updated Tick marks docs to highlight accessibleLabel property.
1Copenut Apr 11, 2024
bd2275e
Linting error on target declaration.
1Copenut Apr 11, 2024
cb7bfe8
Added changelog for 7675.
1Copenut Apr 11, 2024
20d11d6
Removing aria-valuenow attribute because it is not needed for SR anno…
1Copenut Apr 12, 2024
8372187
Refactored handleAriaValueText into one ternary from two guard clauses.
1Copenut Apr 12, 2024
7a2b1ca
Refactoring ternary for better readability.
1Copenut Apr 12, 2024
1a1f48d
Refactored handleAriaValueText to allow string labels.
1Copenut Apr 15, 2024
5ef3d4e
Updated test logic to include label typeof string.
1Copenut Apr 15, 2024
b8439df
Updated docs to illustrate aria-valuetext with label typeof string.
1Copenut Apr 15, 2024
7b7a870
Update changelogs/upcoming/7675.md
1Copenut Apr 16, 2024
08c8aa3
Update src/components/form/range/range.tsx
1Copenut Apr 16, 2024
0ccc7a4
[PR feedback] tests
cee-chen Apr 16, 2024
fed091f
sorry Trevor!
cee-chen Apr 16, 2024
f3b701e
Update src-docs/src/views/range/range_example.js
1Copenut Apr 16, 2024
87ea5d5
Update src/components/form/range/range.tsx
1Copenut Apr 16, 2024
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
15 changes: 15 additions & 0 deletions src/components/form/range/range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ export class EuiRangeClass extends Component<
});
};

handleAriaValueNow = (currentVal: string | number): number | undefined => {
if (!currentVal) return;

let ariaValueNow;
let target = Number(currentVal); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number#return_value

if (!Number.isNaN(target)) {
ariaValueNow = target;
return ariaValueNow;
}

return ariaValueNow; // undefined
};

handleAriaValueText = (
ticks: EuiRangeTick[],
currentVal: string | number
Expand Down Expand Up @@ -245,6 +259,7 @@ export class EuiRangeClass extends Component<
ariaValueText={
ticks ? this.handleAriaValueText(ticks, value) : undefined
}
ariaValueNow={this.handleAriaValueNow(value)}
id={showInput ? undefined : id} // Attach id only to the input if there is one
name={name}
min={min}
Expand Down
3 changes: 3 additions & 0 deletions src/components/form/range/range_slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface EuiRangeSliderProps
thumbColor?: EuiRangeLevel['color'];
onResize: EuiResizeObserverProps['onResize'];
ariaValueText?: string;
ariaValueNow?: number;
}

export const EuiRangeSlider: FunctionComponent<EuiRangeSliderProps> = ({
Expand All @@ -71,6 +72,7 @@ export const EuiRangeSlider: FunctionComponent<EuiRangeSliderProps> = ({
thumbColor,
onResize,
ariaValueText,
ariaValueNow,
...rest
}) => {
const classes = classNames('euiRangeSlider', className);
Expand All @@ -97,6 +99,7 @@ export const EuiRangeSlider: FunctionComponent<EuiRangeSliderProps> = ({
{(resizeRef) => (
<input
aria-valuetext={ariaValueText}
aria-valuenow={ariaValueNow}
1Copenut marked this conversation as resolved.
Show resolved Hide resolved
ref={resizeRef}
type="range"
id={id}
Expand Down