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

[Paper] Adding PaperComponent property makes the Autocomplete scroll to top on change #31073

Closed
2 tasks done
faunti opened this issue Feb 14, 2022 · 8 comments
Closed
2 tasks done
Labels
component: autocomplete This is the name of the generic UI component, not the React module! component: Paper This is the name of the generic UI component, not the React module!

Comments

@faunti
Copy link

faunti commented Feb 14, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

If I have set a custom PaperComponent and I scroll down the list and select an item, I am scrolled back to top automatically.

Expected behavior 🤔

If I have set a custom PaperComponent and I scroll down the list and select an item, I should stay scrolled down to that item.

Steps to reproduce 🕹

Steps:

  1. Go to demo: https://stackblitz.com/edit/react-vr2zm1?file=demo.js
  2. Scroll down to 1957's 12 angry men (or any other item down the list)

Result: You get scrolled to the top of the list.

Context 🔦

If I want to use custom Paper Component to set custom class name or elevation, I get degraded experience. I am currently using a workaround to set the class name through the classes property.

Your environment 🌎

No response

@faunti faunti added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 14, 2022
@danilo-leal danilo-leal changed the title Adding PaperComponent property makes Autocomplete scroll to top on change [Paper] Adding PaperComponent property makes the Autocomplete scroll to top on change Feb 14, 2022
@danilo-leal danilo-leal added component: Paper This is the name of the generic UI component, not the React module! component: autocomplete This is the name of the generic UI component, not the React module! and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 14, 2022
@passpe
Copy link

passpe commented Mar 30, 2022

I have the same problem, are there any updates?

@rossmuego
Copy link

I am also experiencing this behaviour, an update/workaround would be greatly appreciated.

@ZeeshanTamboli ZeeshanTamboli added the bug 🐛 Something doesn't work label Apr 15, 2022
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Apr 15, 2022

Yes it's a bug that passing a custom Paper component is causing the issue to scroll on top.

However, if you just want to have props applied to Paper component, instead of passing a custom component you can use componentsProps.paper slot directly to pass the Paper props.

See: https://stackblitz.com/edit/react-vr2zm1-zkbquf?file=demo.js

This alternative solution fixes the issue.

@nick-kolesnikov
Copy link

@ZeeshanTamboli nice to have this workaround, but it's not enough unfortunately. componentsProps allows to pass props only to paper and clearIndicator but the issue is reproducible with custom PopperComponent too

@ZeeshanTamboli
Copy link
Member

I deep dived into it. This issue happens because the custom paper component is defined inline within the PaperComponent prop, so it causes a rerender since React thinks it's a complete different component. While rerendering the autocomplete is scrolled to the top.

You can fix the issue by memoizing the Paper component or defining it outside the main component. See the following Stackblitz for the second option: https://stackblitz.com/edit/react-vr2zm1-xhhkth?file=demo.js

I'm closing this issue since there is no action for us.

@osv93
Copy link

osv93 commented Jul 19, 2023

This issue is still happening, are there any updates?

@nimishkr28
Copy link

How to add custom prop to the CustomPaperComponent so that it doesn't auto scrolls to the top?

@ZeeshanTamboli
Copy link
Member

How to add custom prop to the CustomPaperComponent so that it doesn't auto scrolls to the top?

@nimishkr28 You can provide those props to the slotProps.paper prop in the Autocomplete component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: autocomplete This is the name of the generic UI component, not the React module! component: Paper This is the name of the generic UI component, not the React module!
Projects
None yet
Development

No branches or pull requests

8 participants