Skip to content

Commit

Permalink
[Select] Simplify the demos (remove ref) (#20076)
Browse files Browse the repository at this point in the history
  • Loading branch information
captain-yossarian committed Mar 13, 2020
1 parent e89ddfd commit 35dae27
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 40 deletions.
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/NativeSelects.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ export default function NativeSelects() {
name: 'hai',
});

const inputLabel = React.useRef(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current.offsetWidth);
}, []);

const handleChange = name => event => {
setState({
...state,
Expand Down Expand Up @@ -200,14 +194,12 @@ export default function NativeSelects() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} htmlFor="outlined-age-native-simple">
Age
</InputLabel>
<InputLabel htmlFor="outlined-age-native-simple">Age</InputLabel>
<Select
native
value={state.age}
onChange={handleChange('age')}
labelWidth={labelWidth}
label="Age"
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/NativeSelects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,6 @@ export default function NativeSelects() {
name: 'hai',
});

const inputLabel = React.useRef<HTMLLabelElement>(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current!.offsetWidth);
}, []);

const handleChange = (name: keyof typeof state) => (
event: React.ChangeEvent<{ value: unknown }>,
) => {
Expand Down Expand Up @@ -204,14 +198,12 @@ export default function NativeSelects() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} htmlFor="outlined-age-native-simple">
Age
</InputLabel>
<InputLabel htmlFor="outlined-age-native-simple">Age</InputLabel>
<Select
native
value={state.age}
onChange={handleChange('age')}
labelWidth={labelWidth}
label="Age"
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/SimpleSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ export default function SimpleSelect() {
const classes = useStyles();
const [age, setAge] = React.useState('');

const inputLabel = React.useRef(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current.offsetWidth);
}, []);

const handleChange = event => {
setAge(event.target.value);
};
Expand Down Expand Up @@ -195,15 +189,13 @@ export default function SimpleSelect() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} id="demo-simple-select-outlined-label">
Age
</InputLabel>
<InputLabel id="demo-simple-select-outlined-label">Age</InputLabel>
<Select
labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined"
value={age}
onChange={handleChange}
labelWidth={labelWidth}
label="Age"
>
<MenuItem value="">
<em>None</em>
Expand Down
12 changes: 2 additions & 10 deletions docs/src/pages/components/selects/SimpleSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ export default function SimpleSelect() {
const classes = useStyles();
const [age, setAge] = React.useState('');

const inputLabel = React.useRef<HTMLLabelElement>(null);
const [labelWidth, setLabelWidth] = React.useState(0);
React.useEffect(() => {
setLabelWidth(inputLabel.current!.offsetWidth);
}, []);

const handleChange = (event: React.ChangeEvent<{ value: unknown }>) => {
setAge(event.target.value as string);
};
Expand Down Expand Up @@ -197,15 +191,13 @@ export default function SimpleSelect() {
<FormHelperText>Required</FormHelperText>
</FormControl>
<FormControl variant="outlined" className={classes.formControl}>
<InputLabel ref={inputLabel} id="demo-simple-select-outlined-label">
Age
</InputLabel>
<InputLabel id="demo-simple-select-outlined-label">Age</InputLabel>
<Select
labelId="demo-simple-select-outlined-label"
id="demo-simple-select-outlined"
value={age}
onChange={handleChange}
labelWidth={labelWidth}
label="Age"
>
<MenuItem value="">
<em>None</em>
Expand Down

0 comments on commit 35dae27

Please sign in to comment.