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

[Select] Simplify the demos (remove ref) #20076

Merged
merged 5 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
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