useComboBox always grabbing focus on render
FredrikMWold opened this issue Β· comments
downshift
version: 8.3.2node
version: v18.19.0npm
(oryarn
) version: 10.2.3
Relevant code or config
useEffect(() => {
if (isInitialMount) {
return
}
previousResultCountRef.current = items.length
})
// Focus the toggle button on first render if required.
useEffect(() => {
const focusOnOpen = getInitialValue(props, 'isOpen')
if (focusOnOpen && toggleButtonRef.current) {
toggleButtonRef.current.focus()
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
What you did:
What happened: Since useRef returns an object the if statment will always be true
Reproduction repository:
Problem description: When rendered the component always grabs focus
Suggested solution: if (isInitialMount)
-> if (isInitialMount.current)
Agreed, this is a problem for me too. Certainly looks to be attributable to the 8.3.1 -> 8.3.2 update.
This is also bugged on useSelect
, we updated our dropdown to use Downshift 8.3.2
and now it focuses the last dropdown on the page (and scrolls it into view): https://sparkui.vercel.app/?path=/docs/components-dropdown--docs
Enregistrement.de.l.ecran.2024-02-29.a.17.34.50.mov
π This issue has been resolved in version 8.3.3 π
The release is available on:
Your semantic-release bot π¦π