File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import StepInput from "../../src/StepInput.js" ;
2+ import Label from "../../src/Label.js" ;
23import { setLanguage } from "@ui5/webcomponents-base/dist/config/Language.js" ;
34import "../../src/Assets.js" ;
45
@@ -950,4 +951,24 @@ describe("Validation inside form", () => {
950951 cy . get ( "#stepInput:invalid" )
951952 . should ( "not.exist" , "StepInput with value lower than max should not have :invalid CSS class" ) ;
952953 } ) ;
954+ } ) ;
955+
956+ describe ( "Accessibility" , ( ) => {
957+ it ( "should have correct aria-label when associated with a label via 'for' attribute" , ( ) => {
958+ const labelText = "Quantity" ;
959+
960+ cy . mount (
961+ < >
962+ < Label for = "stepInput" > { labelText } </ Label >
963+ < StepInput id = "stepInput" > </ StepInput >
964+ </ >
965+ ) ;
966+
967+ cy . get ( "[ui5-step-input]" )
968+ . shadow ( )
969+ . find ( "[ui5-input]" )
970+ . shadow ( )
971+ . find ( "input" )
972+ . should ( "have.attr" , "aria-label" , labelText ) ;
973+ } ) ;
953974} ) ;
Original file line number Diff line number Diff line change @@ -227,3 +227,21 @@ describe("General interactions in form", () => {
227227 } ) ;
228228
229229} ) ;
230+
231+ describe ( "Accessibility" , ( ) => {
232+ it ( "should have correct aria-label when associated with a label via 'for' attribute" , ( ) => {
233+ const labelText = "Enable notifications" ;
234+
235+ cy . mount (
236+ < >
237+ < Label for = "switch" > { labelText } </ Label >
238+ < Switch id = "switch" > </ Switch >
239+ </ >
240+ ) ;
241+
242+ cy . get ( "[ui5-switch]" )
243+ . shadow ( )
244+ . find ( ".ui5-switch-root" )
245+ . should ( "have.attr" , "aria-label" , labelText ) ;
246+ } ) ;
247+ } ) ;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ import {
2323import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js" ;
2424import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
2525import ValueState from "@ui5/webcomponents-base/dist/types/ValueState.js" ;
26- import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js" ;
26+ import { getEffectiveAriaLabelText , getAssociatedLabelForTexts } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js" ;
2727import type { Timeout } from "@ui5/webcomponents-base/dist/types.js" ;
2828import type { IFormInputElement } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js" ;
2929import { submitForm } from "@ui5/webcomponents-base/dist/features/InputElementsFormSupport.js" ;
@@ -391,7 +391,7 @@ class StepInput extends UI5Element implements IFormInputElement {
391391 get accInfo ( ) : InputAccInfo {
392392 return {
393393 "ariaRequired" : this . required ,
394- "ariaLabel" : getEffectiveAriaLabelText ( this ) ,
394+ "ariaLabel" : getEffectiveAriaLabelText ( this ) || getAssociatedLabelForTexts ( this ) ,
395395 } ;
396396 }
397397
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import {
1010} from "@ui5/webcomponents-base/dist/Keys.js" ;
1111import i18n from "@ui5/webcomponents-base/dist/decorators/i18n.js" ;
1212import type I18nBundle from "@ui5/webcomponents-base/dist/i18nBundle.js" ;
13- import { getEffectiveAriaLabelText } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js" ;
13+ import { getEffectiveAriaLabelText , getAssociatedLabelForTexts } from "@ui5/webcomponents-base/dist/util/AccessibilityTextsHelper.js" ;
1414import "@ui5/webcomponents-icons/dist/accept.js" ;
1515import "@ui5/webcomponents-icons/dist/decline.js" ;
1616import "@ui5/webcomponents-icons/dist/less.js" ;
@@ -320,7 +320,7 @@ class Switch extends UI5Element implements IFormInputElement {
320320 }
321321
322322 get ariaLabelText ( ) {
323- return [ getEffectiveAriaLabelText ( this ) , this . hiddenText ] . join ( " " ) . trim ( ) ;
323+ return [ getEffectiveAriaLabelText ( this ) || getAssociatedLabelForTexts ( this ) , this . hiddenText ] . join ( " " ) . trim ( ) ;
324324 }
325325}
326326
Original file line number Diff line number Diff line change @@ -191,6 +191,18 @@ <h3>Form validation</h3>
191191 </ form >
192192 </ section >
193193
194+
195+ < h3 > Accessibility</ h3 >
196+ < section >
197+ < ui5-label for ="stepInputLabel "> In Cart:</ ui5-label >
198+ < ui5-step-input id ="stepInputLabel "
199+ value ="3 "
200+ min ="0 "
201+ max ="10 "
202+ step ="1 "
203+ > </ ui5-step-input >
204+ </ section >
205+
194206 < script >
195207 const labelChange = document . getElementById ( 'myLabelChange' ) ;
196208 const siCozy = document . getElementById ( 'stepInputCozy' ) ;
Original file line number Diff line number Diff line change @@ -108,6 +108,15 @@ <h3>sap_horizon</h3>
108108 < ui5-switch > </ ui5-switch >
109109 < ui5-switch checked > </ ui5-switch >
110110 </ div >
111+
112+ < h3 > Accessibility</ h3 >
113+ < section >
114+ < ui5-label for ="switchLabel "> Do you Agree?</ ui5-label >
115+ < ui5-switch id ="switchLabel "
116+ text-on ="Yes "
117+ text-off ="No "
118+ > </ ui5-switch >
119+ </ section >
111120</ body >
112121
113122< script >
You can’t perform that action at this time.
0 commit comments