question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Bug

  • StackBlitz URL.

  • Steps to reproduce

    1. Focus on the input field
    2. Type a, and wait for suggestions to appear
    3. Press Up/Down arrow key to navigate through the suggestions

    Observed behavior: Suggestions get highlighted on pressing up/down keys (working as expected). But, the scrollbar remains at the top.

Expected behavior: Scrollbar should move according to the highlighted suggestion.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:6

github_iconTop GitHub Comments

3reactions
bdmasoncommented, Aug 13, 2019

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}
  />
1reaction
JordanDDischcommented, Feb 27, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Material UI React-Autosuggest Scrollbar not working on ...
Material UI React-Autosuggest Scrollbar not working on selecting options ... arrow key. option is highlighted but scrollbar does not move.
Read more >
Scrolling with Page Up/Down Keys in React-Window
But the problem is that when you click on an item in a list, you can't scroll up/down using keys. such as Page...
Read more >
Autocomplete API - Material UI - MUI
Name Type Default options * array renderInput * func autoComplete bool false
Read more >
Scrolling | Angular Material
The scrolling package provides helpers for directives that react to scroll events. link cdkScrollable and ScrollDispatcher. The cdkScrollable directive and ...
Read more >
A Guide on Material UI AutoComplete in React - Refine Dev
We'll discover the Material UI (MUI) AutoComplete component with ... An array of movie objects with 'title' as the key and the movie...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found