Material-ui: customizing Select's Paper with a forwardRef looses style on the way

Created on 4 Jul 2019  ·  4Comments  ·  Source: mui-org/material-ui


I'm trying to customize the Paper in the Select component, to add "clear" and "select all" buttons.
I need to pass props to my customized paper so I extracted it to a new component using forwardRef.

But when selecting an option, the menu looses its positioning attributes, and it goes on the top-left on my screen.

  • [x] This is not a v0.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 🤔


The Paper should not move

Current Behavior 😯


The paper moves.

Steps to Reproduce 🕹


Link: https://codesandbox.io/s/material-ui-responsive-table-butui

Context 🔦


I want to do this
image

Your Environment 🌎

| Tech | Version |
|--------------|---------|
| Material-UI | v4.1.3 |
| React | 16.8.6 |
| Browser | chrome Version 75.0.3770.100 (Official Build) (64-bit) |
| TypeScript | no |
| etc. | |

Thanks for the help if I'm mistaken !

question

Most helpful comment

Like this?

    <Select
      multiple
      value={personName}
      onChange={handleChange}
      input={<Input id="select-multiple" />}
      MenuProps={{
        PaperProps: {
          Foo: 'Foo', 
          component: B
        }
      }}
    >

All 4 comments

@raphaelbadia You are creating a new component at each render. React will unmount and remount it. We don't handle that well. Using the same component seems to solve the issue: https://codesandbox.io/s/material-ui-responsive-table-rf87l.

Like this?

    <Select
      multiple
      value={personName}
      onChange={handleChange}
      input={<Input id="select-multiple" />}
      MenuProps={{
        PaperProps: {
          Foo: 'Foo', 
          component: B
        }
      }}
    >

Oh it works perfectly, thanks a lot !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

FranBran picture FranBran  ·  3Comments

rbozan picture rbozan  ·  3Comments

newoga picture newoga  ·  3Comments

sys13 picture sys13  ·  3Comments

TimoRuetten picture TimoRuetten  ·  3Comments