Skip to content

Commit eda250f

Browse files
dobrinyonkovfifoosid
authored andcommitted
fix: (ui5-li): add accessible name to single select radio button (#3842)
1 parent 3ea8cad commit eda250f

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

packages/main/src/ListItem.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
{{#if modeSingleSelect}}
6363
<ui5-radiobutton
6464
?disabled="{{isInactive}}"
65+
accessible-name="{{_accInfo.ariaLabelRadioButton}}"
6566
tabindex="-1"
6667
id="{{_id}}-singleSelectionElement"
6768
class="ui5-li-singlesel-radiobtn"

packages/main/src/ListItem.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ListItemBase from "./ListItemBase.js";
88
import RadioButton from "./RadioButton.js";
99
import CheckBox from "./CheckBox.js";
1010
import Button from "./Button.js";
11-
import { DELETE, ARIA_LABEL_LIST_ITEM_CHECKBOX } from "./generated/i18n/i18n-defaults.js";
11+
import { DELETE, ARIA_LABEL_LIST_ITEM_CHECKBOX, ARIA_LABEL_LIST_ITEM_RADIO_BUTTON } from "./generated/i18n/i18n-defaults.js";
1212

1313
// Styles
1414
import styles from "./generated/themes/ListItem.css.js";
@@ -322,6 +322,7 @@ class ListItem extends ListItemBase {
322322
ariaExpanded: undefined,
323323
ariaLevel: undefined,
324324
ariaLabel: this.i18nBundle.getText(ARIA_LABEL_LIST_ITEM_CHECKBOX),
325+
ariaLabelRadioButton: this.i18nBundle.getText(ARIA_LABEL_LIST_ITEM_RADIO_BUTTON),
325326
listItemAriaLabel: undefined,
326327
};
327328
}

packages/main/src/RadioButton.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
aria-checked="{{selected}}"
44
aria-readonly="{{ariaReadonly}}"
55
aria-disabled="{{ariaDisabled}}"
6-
aria-labelledby="{{ariaLabelledBy}}"
6+
aria-label="{{ariaLabelText}}"
77
aria-describedby="{{ariaDescribedBy}}"
88
tabindex="{{tabIndex}}"
99
dir="{{effectiveDir}}"

packages/main/src/RadioButton.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ const metadata = {
162162
type: Boolean,
163163
},
164164

165+
/**
166+
* Defines the text alternative of the component.
167+
* If not provided a default text alternative will be set, if present.
168+
*
169+
* @type {string}
170+
* @defaultvalue ""
171+
* @private
172+
* @since 1.0.0-rc.16
173+
*/
174+
accessibleName: {
175+
type: String,
176+
},
177+
165178
_tabIndex: {
166179
type: String,
167180
defaultValue: "-1",
@@ -383,8 +396,8 @@ class RadioButton extends UI5Element {
383396
return this.disabled ? "true" : undefined;
384397
}
385398

386-
get ariaLabelledBy() {
387-
return this.text ? `${this._id}-label` : undefined;
399+
get ariaLabelText() {
400+
return [this.text, this.accessibleName].filter(Boolean).join(" ");
388401
}
389402

390403
get ariaDescribedBy() {

packages/main/src/i18n/messagebundle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ LIST_ITEM_SELECTED=Selected
9797
#XBUT: List Multi Selection Mode Checkbox aria-label text
9898
ARIA_LABEL_LIST_ITEM_CHECKBOX = Multiple Selection mode.
9999

100+
#XBUT: List Single Selection Mode RadioButton aria-label text
101+
ARIA_LABEL_LIST_ITEM_RADIO_BUTTON=Item Selection.
102+
100103
#XTOL: Tooltip of messgae strip close button
101104
MESSAGE_STRIP_CLOSE_BUTTON=Message Strip Close
102105

packages/main/test/pages/RadioButton.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
<ui5-input id="field"></ui5-input>
9292
</section>
9393

94+
<section>
95+
<ui5-radio-button id="rb-acc-name" accessible-name="Sample Label"></ui5-radio-button>
96+
<ui5-radio-button id="rb-acc-name-text" text="Sample Text" accessible-name="Sample Label"></ui5-radio-button>
97+
</section>
98+
9499
<p>*Params</p>
95100
<p>
96101
<ui5-label>- for compact add 'ui5-content-density-compact' class to any dom element</ui5-label>

packages/main/test/specs/RadioButton.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,4 +153,14 @@ describe("RadioButton general interaction", () => {
153153
assert.strictEqual(truncatingRbHeight, RADIOBUTTON_DEFAULT_HEIGHT, "The size of the radiobutton is : " + truncatingRbHeight);
154154
assert.ok(wrappingRbHeight > RADIOBUTTON_DEFAULT_HEIGHT, "The size of the radiobutton is more than: " + RADIOBUTTON_DEFAULT_HEIGHT);
155155
});
156+
157+
it("tests accessibleName", () => {
158+
const rbAccName = browser.$("#rb-acc-name");
159+
const rbAccNameText = browser.$("#rb-acc-name-text");
160+
const RADIOBUTTON_LABEL = "Sample Label";
161+
const RADIOBUTTON_TEXT = "Sample Text";
162+
163+
assert.strictEqual(rbAccName.getProperty("ariaLabelText"), RADIOBUTTON_LABEL, "The ariaLabelledByText includes the accessibleName.");
164+
assert.strictEqual(rbAccNameText.getProperty("ariaLabelText"), `${RADIOBUTTON_TEXT} ${RADIOBUTTON_LABEL}`, "The ariaLabelledByText includes both the text and the accessibleName.");
165+
});
156166
});

0 commit comments

Comments
 (0)