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

useComboBox always grabbing focus on render #1574

Closed
FredrikMWold opened this issue Feb 28, 2024 · 4 comments · Fixed by #1575
Closed

useComboBox always grabbing focus on render #1574

FredrikMWold opened this issue Feb 28, 2024 · 4 comments · Fixed by #1575
Labels

Comments

@FredrikMWold
Copy link
Contributor

FredrikMWold commented Feb 28, 2024

  • downshift version: 8.3.2
  • node version: v18.19.0
  • npm (or yarn) 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)

@FredrikMWold FredrikMWold changed the title useComboBox grabbing focus on render useComboBox always grabbing focus on render Feb 28, 2024
@PhilipSampson
Copy link

Agreed, this is a problem for me too. Certainly looks to be attributable to the 8.3.1 -> 8.3.2 update.

@Powerplex
Copy link

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

@silviuaavram
Copy link
Collaborator

silviuaavram commented Feb 29, 2024 via email

Copy link

github-actions bot commented Mar 1, 2024

🎉 This issue has been resolved in version 8.3.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants