Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrollable listbox not focusing first item #3139

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions content/patterns/listbox/examples/js/listbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ aria.Listbox = class Listbox {
if (this.activeDescendant) {
const listitem = document.getElementById(this.activeDescendant);
listitem.scrollIntoView({ block: 'nearest', inline: 'nearest' });
} else {
this.focusFirstItem();
}
}

Expand Down
4 changes: 4 additions & 0 deletions content/patterns/listbox/examples/listbox-scrollable.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ <h2 id="ex_label">Example</h2>
<div>
<span id="ss_elem" class="listbox-label">Transuranium elements:</span>
<ul id="ss_elem_list" tabindex="0" role="listbox" aria-labelledby="ss_elem">
<li id="ss_elem_None" role="option">
<span class="checkmark" aria-hidden="true"></span>
None
</li>
<li id="ss_elem_Np" role="option">
<span class="checkmark" aria-hidden="true"></span>
Neptunium
Expand Down
4 changes: 2 additions & 2 deletions test/tests/listbox_scrollable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const ex = {
listboxSelector: '#ex [role="listbox"]',
optionSelector: '#ex [role="option"]',
spanSelector: '#ex [role="option"] span.checkmark',
numOptions: 26,
firstOptionSelector: '#ex #ss_elem_Np',
numOptions: 27,
firstOptionSelector: '#ex #ss_elem_None',
};

// Attributes
Expand Down
Loading