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

feat(ui5-segmentedbutton): implement accessibility spec #1475

Merged
merged 4 commits into from
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 3 additions & 6 deletions packages/main/src/SegmentedButton.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
@click="{{_onclick}}"
@focusin="{{_onfocusin}}"
class="ui5-segmentedbutton-root"
role="radiogroup"
role="group"
aria-roledescription="{{ariaDescription}}"
>
{{#each this.buttons}}
<div class="ui5-segmentedbutton-item" role="radio" aria-checked="{{this.pressed}}">
<slot name="{{this._individualSlot}}"></slot>
</div>
{{/each}}
<slot></slot>
</div>
20 changes: 13 additions & 7 deletions packages/main/src/SegmentedButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
import ItemNavigation from "@ui5/webcomponents-base/dist/delegate/ItemNavigation.js";
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
import ResizeHandler from "@ui5/webcomponents-base/dist/delegate/ResizeHandler.js";
import { SEGMENTEDBUTTON_ARIA_DESCRIPTION } from "./generated/i18n/i18n-defaults.js";

// Template
import SegmentedButtonTemplate from "./generated/templates/SegmentedButtonTemplate.lit.js";
Expand Down Expand Up @@ -31,10 +33,6 @@ const metadata = {
"default": {
propertyName: "buttons",
type: HTMLElement,
individualSlots: true,
listenFor: {
include: ["pressed"],
},
},
},
events: /** @lends sap.ui.webcomponents.main.SegmentedButton.prototype */ {
Expand Down Expand Up @@ -94,6 +92,10 @@ class SegmentedButton extends UI5Element {
return SegmentedButtonCss;
}

static async onDefine() {
await fetchI18nBundle("@ui5/webcomponents");
}

constructor() {
super();
this.initItemNavigation();
Expand All @@ -103,6 +105,7 @@ class SegmentedButton extends UI5Element {
this.hasPreviouslyFocusedItem = false;

this._handleResizeBound = this._handleResize.bind(this);
this.i18nBundle = getI18nBundle("@ui5/webcomponents");
}

onEnterDOM() {
Expand Down Expand Up @@ -179,15 +182,14 @@ class SegmentedButton extends UI5Element {

_handleResize() {
const parentWidth = this.parentNode.offsetWidth;
const items = Array.from(this.shadowRoot.querySelectorAll(".ui5-segmentedbutton-item"));

if (!this.style.width || this.percentageWidthSet) {
this.style.width = `${Math.max(...this.widths) * this.buttons.length}px`;
this.absoluteWidthSet = true;
}

items.forEach(item => {
item.style.width = "100%";
this.buttons.forEach(button => {
button.style.width = "100%";
});

if (parentWidth <= this.offsetWidth && this.absoluteWidthSet) {
Expand All @@ -206,6 +208,10 @@ class SegmentedButton extends UI5Element {
get selectedButton() {
return this._selectedButton;
}

get ariaDescription() {
return this.i18nBundle.getText(SEGMENTEDBUTTON_ARIA_DESCRIPTION);
}
}

SegmentedButton.define();
Expand Down
3 changes: 3 additions & 0 deletions packages/main/src/i18n/messagebundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ MULTIINPUT_SHOW_MORE_TOKENS={0} More
#XTOL: Tooltip for panel expand title
PANEL_ICON=Expand/Collapse

#XACT: ARIA description for the segmented button
SEGMENTEDBUTTON_ARIA_DESCRIPTION=Segmented button
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really the right text? Isn't "Segmented button" a term only we know, and not meant for the end user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the specification given me by @elenastoyanovaa .
Eli, I think you can give more information?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is the right text. Since the component/control is specific we are adding an aria-roledescription according to Aria 1.1. This is already discussed and will also be implemented in openui5.


#XACT: ARIA announcement for the switch on
SWITCH_ON=On

Expand Down
1 change: 0 additions & 1 deletion packages/main/src/themes/SegmentedButton.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
width: 100%;
}

::slotted(ui5-togglebutton:nth-child(odd)) {
Expand Down