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

Add option for forwarding ref to input element. #46

Open
jondavidjohn opened this issue Dec 8, 2020 · 0 comments
Open

Add option for forwarding ref to input element. #46

jondavidjohn opened this issue Dec 8, 2020 · 0 comments

Comments

@jondavidjohn
Copy link

jondavidjohn commented Dec 8, 2020

If I want to programatically .focus() the input element, I have to use findDOMNode which is deprecated and on the way out.

It would be really useful to expose an option to pass a ref so I could manipulate the input field.

For example, using a keyboard shortcut and mousetrap.

export default function Omnisearch () {
  const inputRef = useRef(null)

  const focusSearch = (e) => {
    e.preventDefault()
    inputRef.focus()
  }

  useMousetrap('/', focusSearch)
  useMousetrap('s', focusSearch)

  return (
    <Omnibar
      inputRef={inputRef}
    />
  )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant