Skip to content

Commit

Permalink
fix(ui5-slider, ui5-range-slider): adjust aria-attributes (#10039)
Browse files Browse the repository at this point in the history
* fix(ui5-slider, ui5-range-slider): adjust aria-attributes

fix accessibility related attributes for slider and range slider
related to: #9547
  • Loading branch information
ndeshev authored Oct 17, 2024
1 parent 478542a commit ed3abfc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
10 changes: 6 additions & 4 deletions packages/main/src/RangeSlider.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{startValue}}"
aria-labelledby="ui5-slider-startHandleDesc"
aria-labelledby="{{_ariaLabelledByStartHandleText}}"
aria-disabled="{{_ariaDisabled}}"
.aria-describedby="{{_ariaDescribedByHandleText}}"
aria-describedby="{{_ariaDescribedByHandleText}}"
aria-keyshortcuts="F2"
>
<ui5-icon name="direction-arrows" mode="Decorative" slider-icon></ui5-icon>
</div>
Expand Down Expand Up @@ -79,9 +80,10 @@
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{endValue}}"
aria-labelledby="ui5-slider-endHandleDesc"
.aria-describedby="{{_ariaDescribedByHandleText}}"
aria-labelledby="{{_ariaLabelledByEndHandleText}}"
aria-describedby="{{_ariaDescribedByHandleText}}"
aria-disabled="{{_ariaDisabled}}"
aria-keyshortcuts="F2"
>
<ui5-icon name="direction-arrows" mode="Decorative" slider-icon></ui5-icon>
</div>
Expand Down
8 changes: 8 additions & 0 deletions packages/main/src/RangeSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,14 @@ class RangeSlider extends SliderBase implements IFormInputElement {
return this.shadowRoot!.querySelector<HTMLElement>(".ui5-slider-progress")!;
}

get _ariaLabelledByStartHandleText() {
return this.accessibleName ? ["ui5-slider-accName", "ui5-slider-startHandleDesc"].join(" ").trim() : "ui5-slider-startHandleDesc";
}

get _ariaLabelledByEndHandleText() {
return this.accessibleName ? ["ui5-slider-accName", "ui5-slider-endHandleDesc"].join(" ").trim() : "ui5-slider-endHandleDesc";
}

get _ariaLabelledByInputText() {
return RangeSlider.i18nBundle.getText(SLIDER_TOOLTIP_INPUT_LABEL);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/Slider.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
aria-valuemin="{{min}}"
aria-valuemax="{{max}}"
aria-valuenow="{{value}}"
aria-labelledby="{{_ariaLabelledByHandleText}} ui5-sliderDesc"
aria-labelledby="{{_ariaLabelledByHandleText}}"
aria-disabled="{{_ariaDisabled}}"
aria-keyshortcuts="F2"
aria-describedby="{{_ariaDescribedByHandleText}}"
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/SliderBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,11 +797,11 @@ abstract class SliderBase extends UI5Element {
}

get _ariaDescribedByHandleText() {
return this.editableTooltip ? "ui5-slider-accName ui5-slider-InputDesc" : undefined;
return this.editableTooltip ? "ui5-slider-InputDesc" : undefined;
}

get _ariaLabelledByHandleText() {
return this.accessibleName ? "ui5-slider-accName" : undefined;
return this.accessibleName ? "ui5-slider-accName ui5-slider-sliderDesc" : "ui5-slider-sliderDesc";
}

get _ariaDescribedByInputText() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/test/specs/Slider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ describe("Accessibility", async () => {
const sliderHandle = await slider.shadow$(".ui5-slider-handle");

assert.strictEqual(await sliderHandle.getAttribute("aria-labelledby"),
"ui5-slider-accName ui5-sliderDesc", "aria-labelledby is set correctly");
"ui5-slider-accName ui5-slider-sliderDesc", "aria-labelledby is set correctly");
assert.strictEqual(await sliderHandle.getAttribute("aria-valuemin"),
`${await slider.getProperty("min")}`, "aria-valuemin is set correctly");
assert.strictEqual(await sliderHandle.getAttribute("aria-valuemax"),
Expand Down

0 comments on commit ed3abfc

Please sign in to comment.