moroshko / react-autosuggest

WAI-ARIA compliant React autosuggest component
http://react-autosuggest.js.org
MIT License
5.97k stars 586 forks source link

React material autosuggest scrollbar not working on up and down arrow keys #598

Open niravhalbe opened 5 years ago

niravhalbe commented 5 years ago

Bug

EverettQuebral commented 5 years ago

Having the same issue here

jwrlee88 commented 5 years ago

Same Issue here. Following for solution.

o-faro commented 5 years ago

Having the same problem I found this one - it did not solve my problem, but may be it will help you https://github.com/moroshko/react-autosuggest/issues/361

bdmason commented 5 years ago

I had this too. This was the best workaround I could come up with:

const Suggestion = ({ isHighlighted, text }) => {
  const itemEl = useRef(null)
  const [bottomRef, bottomInView] = useInView() // from react-intersection-observer
  const [topRef, topInView] = useInView()

  useEffect(() => {
    if (isHighlighted && !bottomInView) {
      itemEl.current.scrollIntoView({ behavior: 'smooth', block: 'end' })
    } else if (isHighlighted && !topInView) {
      itemEl.current.scrollIntoView({ behavior: 'smooth', block: 'start' })
    }
  }, [isHighlighted])

  return (
    <div ref={itemEl}>
      <div ref={topRef} />
        <MenuItem selected={isHighlighted} component="span">
          {text}
        </MenuItem>
      <div ref={bottomRef} />
    </div>
  )
}

const renderSuggestion = (suggestion, { query, isHighlighted }) =>
  <Suggestion
    isHighlighted={isHighlighted}
    text={suggestion.text}
  />
nkov commented 5 years ago

I was experiencing this issue due to a custom container component in renderSuggestionsContainer. Removing this prop fixed the issue for me.

JordanDDisch commented 4 years ago

This was a css issue for me that was fixed by moving the position: absolute; overflow-y: auto; and other custom dropdown styling from the 'ul' class to the results container opened class react-autosuggest__suggestions-container--open.

See this example: https://codepen.io/moroshko/pen/XRgbxR?editors=0110