Skip to content

Commit cbf2461

Browse files
authored
feat(ui5-checkbox): implement ariaLabelledby property (#2272)
1 parent 84eb484 commit cbf2461

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

packages/main/src/CheckBox.hbs

+10-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
aria-checked="{{checked}}"
55
aria-readonly="{{ariaReadonly}}"
66
aria-disabled="{{ariaDisabled}}"
7-
aria-label="{{ariaLabel}}"
7+
aria-label="{{ariaLabelText}}"
88
aria-labelledby="{{ariaLabelledBy}}"
99
aria-describedby="{{ariaDescribedBy}}"
1010
tabindex="{{tabIndex}}"
@@ -18,7 +18,15 @@
1818
<ui5-icon name="accept" class="ui5-checkbox-icon"></ui5-icon>
1919
{{/if}}
2020

21-
<input id="{{_id}}-CB" type='checkbox' ?checked="{{checked}}" ?readonly="{{readonly}}" ?disabled="{{disabled}}" data-sap-no-tab-ref/>
21+
<input
22+
id="{{_id}}-CB"
23+
type='checkbox'
24+
?checked="{{checked}}"
25+
?readonly="{{readonly}}"
26+
?disabled="{{disabled}}"
27+
role="none"
28+
data-sap-no-tab-ref
29+
/>
2230
</div>
2331

2432
{{#if _label.text}}

packages/main/src/CheckBox.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { isDesktop } from "@ui5/webcomponents-base/dist/Device.js";
22
import UI5Element from "@ui5/webcomponents-base/dist/UI5Element.js";
33
import litRender from "@ui5/webcomponents-base/dist/renderer/LitRenderer.js";
44
import { fetchI18nBundle, getI18nBundle } from "@ui5/webcomponents-base/dist/i18nBundle.js";
5+
import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AriaLabelHelper.js";
56
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js";
67
import { getFeature } from "@ui5/webcomponents-base/dist/FeaturesRegistry.js";
78
import { isSpace, isEnter } from "@ui5/webcomponents-base/dist/Keys.js";
@@ -136,6 +137,18 @@ const metadata = {
136137
defaultValue: undefined,
137138
},
138139

140+
/**
141+
* Receives id(or many ids) of the elements that label the checkbox
142+
* @type {String}
143+
* @defaultvalue ""
144+
* @private
145+
* @since 1.0.0-rc.9
146+
*/
147+
ariaLabelledby: {
148+
type: String,
149+
defaultValue: "",
150+
},
151+
139152
_label: {
140153
type: Object,
141154
},
@@ -297,8 +310,16 @@ class CheckBox extends UI5Element {
297310
return this.disabled ? "true" : undefined;
298311
}
299312

313+
get ariaLabelText() {
314+
return getEffectiveAriaLabelText(this);
315+
}
316+
300317
get ariaLabelledBy() {
301-
return this.text ? `${this._id}-label` : undefined;
318+
if (!this.ariaLabelText) {
319+
return this.text ? `${this._id}-label` : undefined;
320+
}
321+
322+
return undefined;
302323
}
303324

304325
get ariaDescribedBy() {

0 commit comments

Comments
 (0)