@@ -23,37 +23,32 @@ import {
2323} from "./generated/i18n/i18n-defaults.js" ;
2424
2525let invisibleText : HTMLElement ;
26- const i18nBundle = new I18nBundle ( "@ui5/webcomponents/main " ) ;
26+ const i18nBundle = new I18nBundle ( "@ui5/webcomponents" ) ;
2727
2828const checkVisibility = ( element : HTMLElement ) : boolean => {
2929 return element . checkVisibility ( ) || getComputedStyle ( element ) . display === "contents" ;
3030} ;
3131
32- const updateInvisibleText = ( element : HTMLElement , text : string | string [ ] = [ ] ) => {
33- const invisibleTextId = "ui5-table-invisible-text" ;
32+ const updateInvisibleText = ( element : any , text : string | string [ ] = [ ] ) => {
3433 if ( ! invisibleText || ! invisibleText . isConnected ) {
3534 invisibleText = document . createElement ( "span" ) ;
36- invisibleText . id = invisibleTextId ;
35+ invisibleText . id = "ui5-table-invisible-text" ;
3736 invisibleText . ariaHidden = "true" ;
3837 invisibleText . style . display = "none" ;
3938 document . body . appendChild ( invisibleText ) ;
4039 }
4140
42- let ariaLabelledBy = ( element . getAttribute ( "aria-labelledby" ) || "" ) . split ( " " ) . filter ( Boolean ) ;
43- const invisibleTextAssociated = ariaLabelledBy . includes ( invisibleTextId ) ;
44-
41+ const ariaLabelledByElements = [ ...( element . ariaLabelledByElements || [ ] ) ] ;
42+ const invisibleTextIndex = ariaLabelledByElements . indexOf ( invisibleText ) ;
4543 text = Array . isArray ( text ) ? text . filter ( Boolean ) . join ( " . " ) . trim ( ) : text . trim ( ) ;
46- if ( text && ! invisibleTextAssociated ) {
47- ariaLabelledBy . push ( invisibleTextId ) ;
48- } else if ( ! text && invisibleTextAssociated ) {
49- ariaLabelledBy = ariaLabelledBy . filter ( id => id !== invisibleTextId ) ;
50- }
51-
5244 invisibleText . textContent = text ;
53- if ( ariaLabelledBy . length > 0 ) {
54- element . setAttribute ( "aria-labelledby" , ariaLabelledBy . join ( " " ) ) ;
55- } else {
56- element . removeAttribute ( "aria-labelledby" ) ;
45+
46+ if ( text && invisibleTextIndex === - 1 ) {
47+ ariaLabelledByElements . unshift ( invisibleText ) ;
48+ element . ariaLabelledByElements = ariaLabelledByElements ;
49+ } else if ( ! text && invisibleTextIndex > - 1 ) {
50+ ariaLabelledByElements . splice ( invisibleTextIndex , 1 ) ;
51+ element . ariaLabelledByElements = ariaLabelledByElements . length ? ariaLabelledByElements : null ;
5752 }
5853} ;
5954
0 commit comments