Skip to content

Commit e806913

Browse files
committed
chore: Update branch with latest issue3193-aria-actions-listbox changes and submodule updates
1 parent 5bc921d commit e806913

4 files changed

Lines changed: 55 additions & 33 deletions

File tree

ARIA/apg/patterns/listbox/examples/listbox-actions.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ lang: en
130130
<h2 id="ex_label">Example</h2>
131131
</div>
132132
<div role="separator" id="ex_start_sep" aria-labelledby="ex_start_sep ex_label" aria-label="Start of"></div>
133-
<div class="offscreen">Last change: <span aria-live="polite" id="ss_live_region"></span></div>
134133
<div id="ex">
135134
<p>
136135
Plan your bucket list: Select an item to view or edit its details. Flag it for follow up if you need to do
@@ -217,22 +216,13 @@ lang: en
217216

218217
<div class="contentColumn">
219218
<div class="listbox-area">
220-
<h3>Details:</h3>
221-
<div id="ss_elem_IronMan_detail_panel" class="js-detailPanel detailPanel is-hidden">
222-
Iron Man content goes here.
223-
</div>
224-
<div id="ss_elem_Everest_detail_panel" class="js-detailPanel detailPanel is-hidden">
225-
Climbing Mount Everest content goes here.
226-
</div>
227-
<div id="ss_elem_Archery_detail_panel" class="js-detailPanel detailPanel is-hidden">
228-
Archery content goes here.
229-
</div>
230-
<div id="ss_elem_GuideDog_detail_panel" class="js-detailPanel detailPanel is-hidden">
231-
Gide dog training content goes here.
232-
</div>
233-
<div id="ss_elem_Airplane_detail_panel" class="js-detailPanel detailPanel is-hidden">
234-
Airplane Building content goes here.
235-
</div>
219+
<h3 id="listboxDetailsLabel">Details:</h3>
220+
<textarea aria-labelledby="listboxDetailsLabel" readonly id="ss_elem_IronMan_detail_panel" class="js-detailPanel detailPanel is-hidden">Iron Man content goes here.</textarea>
221+
<textarea aria-labelledby="listboxDetailsLabel" readonly id="ss_elem_Everest_detail_panel" class="js-detailPanel detailPanel is-hidden">Climbing Mount Everest content goes here.</textarea>
222+
<textarea aria-labelledby="listboxDetailsLabel" readonly id="ss_elem_Archery_detail_panel" class="js-detailPanel detailPanel is-hidden">Archery content goes here.</textarea>
223+
<textarea aria-labelledby="listboxDetailsLabel" readonly id="ss_elem_GuideDog_detail_panel" class="js-detailPanel detailPanel is-hidden">Gide dog training content goes here.</textarea>
224+
<textarea aria-labelledby="listboxDetailsLabel" readonly id="ss_elem_Airplane_detail_panel" class="js-detailPanel detailPanel is-hidden">Airplane Building content goes here.
225+
</textarea>
236226
</div>
237227
</div>
238228
</div>

content-assets/wai-aria-practices/patterns/listbox/examples/css/listbox-actions.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ li {
4747
}
4848

4949
.detailPanel {
50-
margin: 1em 0 0;
51-
padding: 7px 0 0 10px;
5250
min-height: 18em;
5351
border: 1px solid #aaa;
5452
background: white;
53+
height: 100%;
54+
width: 95%;
55+
margin-top: .15em
5556
}
5657

5758
.detailPanel.is-hidden {
@@ -167,7 +168,7 @@ button.delete::before {
167168
white-space: pre;
168169
}
169170

170-
.focusedActionButton {
171+
#ss_elem_list:focus button.focusedActionButton {
171172
color: black !important;
172173
background-color: rgb(226 239 225) !important;
173174
border-color: rgb(0 90 156);

content-assets/wai-aria-practices/patterns/listbox/examples/js/listbox-actions.js

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,24 @@ var aria = aria || {};
2424
aria.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

Comments
 (0)