File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -367,4 +367,24 @@ describe("CheckBox general interaction", () => {
367
367
. find ( "ui5-icon" )
368
368
. should ( "have.attr" , "name" , "tri-state" ) ;
369
369
} ) ;
370
+ } ) ;
371
+
372
+ describe ( "Accessibility" , ( ) => {
373
+ it ( "should announce the associated label when CheckBox is focused" , ( ) => {
374
+ cy . mount (
375
+ < >
376
+ < label for = "cb" > Should be the aria-label</ label >
377
+ < CheckBox id = "cb" > </ CheckBox >
378
+ </ >
379
+ ) ;
380
+
381
+ cy . get ( 'label[for="cb"]' )
382
+ . invoke ( 'text' )
383
+ . then ( ( labelText ) => {
384
+ cy . get ( "[ui5-checkbox]" )
385
+ . shadow ( )
386
+ . find ( ".ui5-checkbox-root" )
387
+ . should ( "have.attr" , "aria-label" , labelText ) ;
388
+ } ) ;
389
+ } ) ;
370
390
} ) ;
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ import jsxRenderer from "@ui5/webcomponents-base/dist/renderer/JsxRenderer.js";
7
7
import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js" ;
8
8
import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
9
9
import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js" ;
10
- import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js" ;
10
+ import { getEffectiveAriaLabelText , getAssociatedLabelForTexts } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js" ;
11
11
import { isSpace , isEnter } from "@ui5/webcomponents-base/dist/Keys.js" ;
12
12
import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js" ;
13
13
import type WrappingType from "./types/WrappingType.js" ;
@@ -400,7 +400,7 @@ class CheckBox extends UI5Element implements IFormInputElement {
400
400
}
401
401
402
402
get ariaLabelText ( ) {
403
- return getEffectiveAriaLabelText ( this ) ;
403
+ return getEffectiveAriaLabelText ( this ) || getAssociatedLabelForTexts ( this ) ;
404
404
}
405
405
406
406
get classes ( ) {
You can’t perform that action at this time.
0 commit comments