Skip to content

Commit

Permalink
add a fallback focus and clean up code comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mcwinter07 committed Oct 3, 2024
1 parent 7972678 commit 5a21407
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe("Stringified object values", () => {
label: "Created by Z-A",
},
]}
selectedKey={'{"sortBy":"creator_name","sortOrder":"asc"}'}
selectedKey='{"sortBy":"creator_name","sortOrder":"asc"}'
/>
)
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const getOptionKeyFromCollection = (
return state.collection.getFirstKey()
}

// This makes the use of query selector less brittle in instances where a failed selector is passed in
/** This makes the use of query selector less brittle in instances where a failed selector is passed in
*/
const safeQuerySelector = (selector: string): HTMLElement | null => {
try {
return document.querySelector(selector)
Expand Down Expand Up @@ -72,6 +73,9 @@ export const ListBox = <Option extends SelectOption>({

if (focusToElement) {
focusToElement.focus()
} else {
// If an element is not found, focus on the listbox. This ensures the list can still be navigated to via keyboard if the keys do not align to the data attributes of the list items.
ref.current?.focus()
}
}
}, [isClientReady])
Expand Down

0 comments on commit 5a21407

Please sign in to comment.