How to avoid Material UI Select focus when option is chosen?

天涯浪子 提交于 2019-12-24 02:08:46

问题


I am trying to make an interface with a pair of Select and Input from Material UI components library. I want the current behaviour for my UI/UX in the next order: 1. User chose option from Select element 2. Inputwill be focused when user chose something from Select

You can see how it's works (see the second Select, because the first one is a native Select, and it's not suitable for my purpose): https://codesandbox.io/s/l4nq3pjjrm

The first one in the example above works great, but I need non-native variant.

How I can do that? Thanks.

P.S. Also, I found that there are another issues with that wrong Select behaviour, take a look for my github post for mo details. (https://github.com/mui-org/material-ui/issues/11964)


回答1:


So if your problem is the focus after the value selection, try this:

1) Import MuiThemeProvider and createMuiTheme on your component:

import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';

2) Then Add this lines of code after your imports (override css):

const theme1 = createMuiTheme({
  overrides: {
    MuiSelect: {
      select: {
        "&:focus": {
          background: "$labelcolor"
        }
      }
    }
  }
});

3) And for the final step, wrap your component that you want to edit with this code:

<MuiThemeProvider theme={theme1}>

// Your Component here

</MuiThemeProvider>

I applied it on your code here



来源:https://stackoverflow.com/questions/51014689/how-to-avoid-material-ui-select-focus-when-option-is-chosen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!