@@ -24,19 +24,24 @@ var aria = aria || {};
2424aria . ListboxActions = class ListboxActions {
2525 constructor ( listboxActionsObject ) {
2626 this . listboxActionsNode = listboxActionsObject ;
27+ this . listboxCurrentItemActionsButtons = [ ] ;
2728 this . activeDescendant = this . listboxActionsNode . getAttribute (
2829 'aria-activedescendant'
2930 ) ;
3031 this . listboxOptionArray = Array . from (
3132 this . listboxActionsNode . querySelectorAll ( '[role="option"]' )
3233 ) ;
33- this . listboxItemCurrent = null ;
34+ this . selectItem ( this . listboxOptionArray [ 0 ] ) ;
35+ this . listboxItemCurrent = this . listboxOptionArray [ 0 ] ;
36+ this . populateCurrentItemActionButtons ( )
3437 this . listboxActiveOption = null ;
3538 this . activeDescendant = null ;
36- this . listboxCurrentItemActionsButtons = [ ] ;
3739 this . listboxCurrentOptionIndex = - 1 ;
3840 this . listboxItemsWithAriaActionsArray = [ ] ;
3941 this . registerActionsEvents ( ) ;
42+ this . useAriaNotify = document . ariaNotify ;
43+ this . setupNotifications ( ) ;
44+ this . ariaLiveRegion ;
4045 }
4146
4247 registerActionsEvents ( ) {
@@ -58,6 +63,25 @@ aria.ListboxActions = class ListboxActions {
5863 ) ;
5964 }
6065 }
66+ setupNotifications ( ) {
67+ if ( ! this . useAriaNotify ) {
68+ this . ariaLiveRegion = document . createElement ( 'div' ) ;
69+ this . ariaLiveRegion . ariaLive = 'assertive' ;
70+ this . ariaLiveRegion . classList . add ( "offscreen" ) ;
71+ document . querySelector ( 'main' ) . appendChild ( this . ariaLiveRegion ) ;
72+ }
73+ }
74+ removeNotificationViaTimeout ( ariaLiveRegion ) {
75+ ariaLiveRegion . innerText = '' ;
76+ }
77+ doNotification ( notificationText ) {
78+ if ( this . useAriaNotify ) {
79+ document . ariaNotify ( notificationText ) ;
80+ } else {
81+ this . ariaLiveRegion . innerText = notificationText ;
82+ setTimeout ( this . removeNotificationViaTimeout , 2000 , this . ariaLiveRegion ) ;
83+ }
84+ }
6185 handleItemChange ( event , item ) {
6286 var updateText = '' ;
6387 switch ( event ) {
@@ -81,8 +105,7 @@ aria.ListboxActions = class ListboxActions {
81105 break ;
82106 }
83107 if ( updateText ) {
84- var ex1LiveRegion = document . getElementById ( 'ss_live_region' ) ;
85- ex1LiveRegion . innerHTML = updateText ;
108+ this . doNotification ( updateText ) ;
86109 }
87110 }
88111 /* Return the next listbox option, if it exists; otherwise, returns null */
@@ -119,8 +142,6 @@ aria.ListboxActions = class ListboxActions {
119142 * Remove all of the selected items from the listbox; Removes the focused items
120143 * in a single select listbox and the items with aria-selected in a multi
121144 * select listbox.
122- * @returns {Array }
123- * An array of items that were removed from the listbox
124145 */
125146 deleteItems ( ) {
126147 let itemToDelete = document . getElementById ( this . activeDescendant ) ;
@@ -182,6 +203,17 @@ aria.ListboxActions = class ListboxActions {
182203 element . removeAttribute ( 'aria-selected' ) ;
183204 }
184205 }
206+ /**
207+ * @description
208+ * Populates the list of action buttons
209+ */
210+ populateCurrentItemActionButtons ( ) {
211+ this . listboxCurrentItemActionsButtons = Array . from (
212+ this . listboxItemCurrent . querySelectorAll (
213+ 'button:not(.hide-actions-button),[role=“button”]:not(.hide-actions-button)'
214+ )
215+ ) ;
216+ }
185217 /**
186218 * @description
187219 * Enable/disable the up/down arrows based on the activeDescendant.
@@ -396,6 +428,7 @@ aria.ListboxActions = class ListboxActions {
396428 }
397429 this . setActiveDescendant ( this . listboxItemsWithAriaActionsArray [ 0 ] ) ;
398430 this . updateArrowUpDownItems ( ) ;
431+ this . populateCurrentItemActionButtons ( ) ;
399432 break ;
400433 case 'js-favorite' :
401434 case 'favorite' :
@@ -412,7 +445,7 @@ aria.ListboxActions = class ListboxActions {
412445 ) ;
413446 this . handleItemChange (
414447 activeButton . ariaPressed == 'true' ? 'favorite' : 'unfavorited' ,
415- [ activeOption ]
448+ activeOption
416449 ) ;
417450 activeOption . classList . toggle ( 'js-favoriteIndication' ) ;
418451 if ( activeOption . classList . contains ( 'js-favoriteIndication' ) ) {
@@ -423,10 +456,12 @@ aria.ListboxActions = class ListboxActions {
423456 case 'uparrow' :
424457 this . moveUpItems ( ) ;
425458 this . updateArrowUpDownItems ( ) ;
459+ this . populateCurrentItemActionButtons ( ) ;
426460 break ;
427461 case 'downarrow' :
428462 this . moveDownItems ( ) ;
429463 this . updateArrowUpDownItems ( ) ;
464+ this . populateCurrentItemActionButtons ( ) ;
430465 break ;
431466 default :
432467 this . selectItem ( event . currentTarget . querySelector ( '.focused' ) ) ;
@@ -478,11 +513,7 @@ aria.ListboxActions = class ListboxActions {
478513 if ( this . listboxItemCurrent ) {
479514 this . focusItem ( this . listboxItemCurrent ) ;
480515 }
481- this . listboxCurrentItemActionsButtons = Array . from (
482- this . listboxItemCurrent . querySelectorAll (
483- 'button:not(.hide-actions-button),[role="button"]:not(.hide-actions-button)'
484- )
485- ) ;
516+ this . populateCurrentItemActionButtons ( ) ;
486517 this . setAriaActions (
487518 this . listboxItemCurrent ,
488519 this . listboxCurrentItemActionsButtons . map ( ( node ) => node . id ) . join ( ' ' )
0 commit comments