@@ -78,7 +78,7 @@ class ColorPicker {
7878 this . #uiManager = editor ?. _uiManager || uiManager ;
7979 this . #eventBus = this . #uiManager. _eventBus ;
8080 this . #defaultColor =
81- editor ?. color ||
81+ editor ?. color ?. toUpperCase ( ) ||
8282 this . #uiManager?. highlightColors . values ( ) . next ( ) . value ||
8383 "#FFFF98" ;
8484
@@ -96,22 +96,25 @@ class ColorPicker {
9696 button . className = "colorPicker" ;
9797 button . tabIndex = "0" ;
9898 button . setAttribute ( "data-l10n-id" , "pdfjs-editor-colorpicker-button" ) ;
99- button . setAttribute ( "aria-haspopup" , true ) ;
99+ button . ariaHasPopup = "true" ;
100+ if ( this . #editor) {
101+ button . ariaControls = `${ this . #editor. id } _colorpicker_dropdown` ;
102+ }
100103 const signal = this . #uiManager. _signal ;
101104 button . addEventListener ( "click" , this . #openDropdown. bind ( this ) , { signal } ) ;
102105 button . addEventListener ( "keydown" , this . #keyDown. bind ( this ) , { signal } ) ;
103106 const swatch = ( this . #buttonSwatch = document . createElement ( "span" ) ) ;
104107 swatch . className = "swatch" ;
105- swatch . setAttribute ( "aria-hidden" , true ) ;
108+ swatch . ariaHidden = " true" ;
106109 swatch . style . backgroundColor = this . #defaultColor;
107110 button . append ( swatch ) ;
108111 return button ;
109112 }
110113
111114 renderMainDropdown ( ) {
112115 const dropdown = ( this . #dropdown = this . #getDropdownRoot( ) ) ;
113- dropdown . setAttribute ( "aria-orientation" , "horizontal" ) ;
114- dropdown . setAttribute ( "aria-labelledby" , "highlightColorPickerLabel" ) ;
116+ dropdown . ariaOrientation = "horizontal" ;
117+ dropdown . ariaLabelledBy = "highlightColorPickerLabel" ;
115118
116119 return dropdown ;
117120 }
@@ -122,9 +125,12 @@ class ColorPicker {
122125 div . addEventListener ( "contextmenu" , noContextMenu , { signal } ) ;
123126 div . className = "dropdown" ;
124127 div . role = "listbox" ;
125- div . setAttribute ( "aria-multiselectable" , false ) ;
126- div . setAttribute ( "aria-orientation" , "vertical" ) ;
128+ div . ariaMultiSelectable = " false" ;
129+ div . ariaOrientation = "vertical" ;
127130 div . setAttribute ( "data-l10n-id" , "pdfjs-editor-colorpicker-dropdown" ) ;
131+ if ( this . #editor) {
132+ div . id = `${ this . #editor. id } _colorpicker_dropdown` ;
133+ }
128134 for ( const [ name , color ] of this . #uiManager. highlightColors ) {
129135 const button = document . createElement ( "button" ) ;
130136 button . tabIndex = "0" ;
@@ -136,7 +142,7 @@ class ColorPicker {
136142 button . append ( swatch ) ;
137143 swatch . className = "swatch" ;
138144 swatch . style . backgroundColor = color ;
139- button . setAttribute ( "aria-selected" , color === this . #defaultColor) ;
145+ button . ariaSelected = color === this . #defaultColor;
140146 button . addEventListener ( "click" , this . #colorSelect. bind ( this , color ) , {
141147 signal,
142148 } ) ;
@@ -231,6 +237,7 @@ class ColorPicker {
231237 signal : this . #uiManager. combinedSignal ( this . #openDropdownAC) ,
232238 } ) ;
233239 }
240+ this . #button. ariaExpanded = "true" ;
234241 if ( this . #dropdown) {
235242 this . #dropdown. classList . remove ( "hidden" ) ;
236243 return ;
@@ -248,6 +255,7 @@ class ColorPicker {
248255
249256 hideDropdown ( ) {
250257 this . #dropdown?. classList . add ( "hidden" ) ;
258+ this . #button. ariaExpanded = "false" ;
251259 this . #openDropdownAC?. abort ( ) ;
252260 this . #openDropdownAC = null ;
253261 }
@@ -283,7 +291,7 @@ class ColorPicker {
283291
284292 const i = this . #uiManager. highlightColors . values ( ) ;
285293 for ( const child of this . #dropdown. children ) {
286- child . setAttribute ( "aria-selected" , i . next ( ) . value === color ) ;
294+ child . ariaSelected = i . next ( ) . value === color . toUpperCase ( ) ;
287295 }
288296 }
289297
0 commit comments