From b0c04c4bf4bae3d2de4b1fed893d250ec27f5de8 Mon Sep 17 00:00:00 2001 From: Wagner Maciel Date: Tue, 19 Nov 2024 15:45:30 +0000 Subject: [PATCH] Scrollable Listbox Example: Ad default value 'None' so first item can be focusable on load (pull #3139) Fixes issue #3138 by adding a new value of 'None' to the list of options and focusing that option by default. This makes the example consistent with the pattern guidance. --- .../examples/js/listbox-collapsible.js | 1 - .../patterns/listbox/examples/js/listbox.js | 2 + .../listbox/examples/listbox-collapsible.html | 1 + .../listbox/examples/listbox-scrollable.html | 4 ++ test/tests/listbox_collapsible.js | 38 ++++++++++--------- test/tests/listbox_grouped.js | 6 +-- test/tests/listbox_scrollable.js | 6 +-- 7 files changed, 34 insertions(+), 24 deletions(-) diff --git a/content/patterns/listbox/examples/js/listbox-collapsible.js b/content/patterns/listbox/examples/js/listbox-collapsible.js index 4beaae9f5c..4002d17a45 100644 --- a/content/patterns/listbox/examples/js/listbox-collapsible.js +++ b/content/patterns/listbox/examples/js/listbox-collapsible.js @@ -53,7 +53,6 @@ class ListboxButton { case 'ArrowDown': evt.preventDefault(); this.showListbox(); - this.listbox.checkKeyPress(evt); break; } } diff --git a/content/patterns/listbox/examples/js/listbox.js b/content/patterns/listbox/examples/js/listbox.js index 632063f25c..6475933057 100644 --- a/content/patterns/listbox/examples/js/listbox.js +++ b/content/patterns/listbox/examples/js/listbox.js @@ -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(); } } diff --git a/content/patterns/listbox/examples/listbox-collapsible.html b/content/patterns/listbox/examples/listbox-collapsible.html index f328baa095..e7015ff1cf 100644 --- a/content/patterns/listbox/examples/listbox-collapsible.html +++ b/content/patterns/listbox/examples/listbox-collapsible.html @@ -66,6 +66,7 @@

Example