'In Material UI v3.6.0 Select Dropdown div flickers / triggers twice
When i am providing less than 100 items to the Select Dropdown its working fine but if i provide more than 100 then the Dropdown flickers/triggers twice. I have checked by putting debug point in the render function but it doesn't reach there after first render. I also put a random no check to see whether its actually re-rendering but even the randomly generated no is same. This is my code:
import React from 'react';
import PropTypes from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import FormControl from '@material-ui/core/FormControl';
import Select from '@material-ui/core/Select';
const styles = theme => ({
root: {
display: 'flex',
flexWrap: 'wrap',
},
formControl: {
margin: theme.spacing.unit,
minWidth: 120,
},
selectEmpty: {
marginTop: theme.spacing.unit * 2,
},
});
class SimpleSelect extends React.Component {
state = {
age: '',
name: 'hai',
labelWidth: 0,
};
constructor(props) {
super(props);
this.filters = [];
}
componentDidMount() {
this.setState({
labelWidth: 0,
});
for (let i = 0; i < 250; i++) {
this.filters.push('----select----' + i);
}
}
handleChange = event => {
this.setState({ [event.target.name]: event.target.value });
};
render() {
const { classes } = this.props;
return (
<form className={classes.root} autoComplete="off">
<FormControl className={classes.formControl}>
<InputLabel htmlFor="age-simple">Filter</InputLabel>
<Select
value={this.state.age}
onChange={this.handleChange}
inputProps={{
name: 'age',
id: 'age-simple',
}}
>
{this.filters && this.filters.map((filter, index) => (
<MenuItem key={'filter-' + index} value={filter}>
{filter}
</MenuItem>
))}
</Select>
</FormControl>
</form>
);
}
}
SimpleSelect.propTypes = {
classes: PropTypes.object.isRequired,
};
export default withStyles(styles)(SimpleSelect);
This behavior is only observed in material-ui v3.6.0.
Edit1: Please have a look at the working codesandbox
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|