Skip to content

Commit

Permalink
Single-select listbox example: Fix aria-selected bug (pull #795)
Browse files Browse the repository at this point in the history
For issue #794, update aria-selected for single-select listbox options where selection follows focus.

Change in listbox/js/listbox.js:
When aria-multiselectable is false, toggle aria-selected when option receives or loses focus.
  • Loading branch information
tryenc authored and mcking65 committed Aug 13, 2018
1 parent c104e0e commit 66229af
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 1 addition & 5 deletions examples/listbox/css/listbox.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

[role="option"] {
display: block;
padding: 0 1em;
padding: 0 1em 0 1.5em;
position: relative;
line-height: 1.8em;
}
Expand All @@ -44,10 +44,6 @@
background: #bde4ff;
}

[role="option"][aria-selected] {
padding-left: 1.5em;
}

[role="option"][aria-selected="true"]::before {
content: '✓';
position: absolute;
Expand Down
7 changes: 6 additions & 1 deletion examples/listbox/js/listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,9 @@ aria.Listbox.prototype.defocusItem = function (element) {
if (!element) {
return;
}

if (!this.multiselectable) {
element.removeAttribute('aria-selected');
}
aria.Utils.removeClass(element, 'focused');
};

Expand All @@ -315,6 +317,9 @@ aria.Listbox.prototype.defocusItem = function (element) {
*/
aria.Listbox.prototype.focusItem = function (element) {
this.defocusItem(document.getElementById(this.activeDescendant));
if (!this.multiselectable) {
element.setAttribute('aria-selected', 'true');
}
aria.Utils.addClass(element, 'focused');
this.listboxNode.setAttribute('aria-activedescendant', element.id);
this.activeDescendant = element.id;
Expand Down

0 comments on commit 66229af

Please sign in to comment.