Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/neat-toes-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

experimental/SelectPanel: Move focus to first item if there is no filter input
16 changes: 10 additions & 6 deletions packages/react/src/drafts/SelectPanel2/SelectPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,16 @@ const Panel: React.FC<SelectPanelProps> = ({
// Autofocus hack: React doesn't support autoFocus for dialog: https://github.com/facebook/react/issues/23301
// tl;dr: react takes over autofocus instead of letting the browser handle it,
// but not for dialogs, so we have to do it
React.useEffect(() => {
if (internalOpen) {
const searchInput = document.querySelector('dialog[open] input') as HTMLInputElement | undefined
searchInput?.focus()
}
}, [internalOpen])
React.useEffect(
function intialFocus() {
if (internalOpen) {
const searchInput = document.querySelector('dialog[open] input') as HTMLInputElement | undefined
if (searchInput) searchInput.focus()
else moveFocusToList()
}
},
[internalOpen],
)

/* Anchored */
const {position} = useAnchoredPosition(
Expand Down