Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Material-UI Select not detecting scroll event

I'm having some trouble understanding how I'm supposed to detect a scroll event with a Select component using Material-UI.

I have a Select that has MenuProps={...}. I want to be able to listen to the scroll event inside this Select, so what I'm doing is putting onScroll inside the MenuProps={...}. But the event is never fired.

What I've already tried:

  • Putting an overflow: 'auto' next to the style object in MenuProps={...}. It results in the list blinking for a second (on top of the Select instead of the bottom) and disappearing.
  • What I have actually is looking like this : https://codesandbox.io/s/autocomplete-not-scrolling-example-k5ltg

Could someone help me please?

like image 214
Pandorque Avatar asked Jun 11 '26 01:06

Pandorque


1 Answers

After digging in the Material-UI source code, I've found that you need to attach the scroll listener to the Paper component, so this is the working code:

MenuProps={{
  PaperProps: {
    onScroll: (event: any) => {
      console.log(event);
      console.log("we scroll");
    }
  },
}}

Live Demo

Edit autocomplete-not-scrolling-example (forked)

like image 184
NearHuscarl Avatar answered Jun 12 '26 15:06

NearHuscarl