omnibar icon indicating copy to clipboard operation
omnibar copied to clipboard

Add option for forwarding ref to input element.

Open jondavidjohn opened this issue 4 years ago • 0 comments

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}
    />
  )
}

jondavidjohn avatar Dec 08 '20 18:12 jondavidjohn