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] Fix incorrect event.target type in onChange #15272

Merged
merged 5 commits into from
Apr 11, 2019
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
132 changes: 132 additions & 0 deletions docs/src/pages/demos/dialogs/MaxWidthDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import React from 'react';
import PropTypes from 'prop-types';
import { createStyles, Theme, withStyles, WithStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Dialog, { DialogProps } from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
import DialogContentText from '@material-ui/core/DialogContentText';
import DialogTitle from '@material-ui/core/DialogTitle';
import FormControl from '@material-ui/core/FormControl';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import InputLabel from '@material-ui/core/InputLabel';
import MenuItem from '@material-ui/core/MenuItem';
import Select from '@material-ui/core/Select';
import Switch from '@material-ui/core/Switch';

const styles = (theme: Theme) =>
createStyles({
form: {
display: 'flex',
flexDirection: 'column',
margin: 'auto',
width: 'fit-content',
},
formControl: {
marginTop: theme.spacing(2),
minWidth: 120,
},
formControlLabel: {
marginTop: theme.spacing(1),
},
});

export type MaxWidthDialogProps = WithStyles<typeof styles>;

export interface MaxWidthDialogState {
open: boolean;
fullWidth: boolean;
maxWidth: DialogProps['maxWidth'];
}

class MaxWidthDialog extends React.Component<MaxWidthDialogProps, MaxWidthDialogState> {
state: MaxWidthDialogState = {
open: false,
fullWidth: true,
maxWidth: 'sm',
};

handleClickOpen = () => {
this.setState({ open: true });
};

handleClose = () => {
this.setState({ open: false });
};

handleMaxWidthChange = (event: React.ChangeEvent<{ value: unknown }>) => {
this.setState({ maxWidth: event.target.value as MaxWidthDialogState['maxWidth'] });
};

handleFullWidthChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.setState({ fullWidth: event.target.checked });
};

render() {
const { classes } = this.props;

return (
<React.Fragment>
<Button variant="outlined" color="primary" onClick={this.handleClickOpen}>
Open max-width dialog
</Button>
<Dialog
fullWidth={this.state.fullWidth}
maxWidth={this.state.maxWidth}
open={this.state.open}
onClose={this.handleClose}
aria-labelledby="max-width-dialog-title"
>
<DialogTitle id="max-width-dialog-title">Optional sizes</DialogTitle>
<DialogContent>
<DialogContentText>
You can set my maximum width and whether to adapt or not.
</DialogContentText>
<form className={classes.form} noValidate>
<FormControl className={classes.formControl}>
<InputLabel htmlFor="max-width">maxWidth</InputLabel>
<Select
value={this.state.maxWidth}
onChange={this.handleMaxWidthChange}
inputProps={{
name: 'max-width',
id: 'max-width',
}}
>
<MenuItem value={false as any}>false</MenuItem>
<MenuItem value="xs">xs</MenuItem>
<MenuItem value="sm">sm</MenuItem>
<MenuItem value="md">md</MenuItem>
<MenuItem value="lg">lg</MenuItem>
<MenuItem value="xl">xl</MenuItem>
</Select>
</FormControl>
<FormControlLabel
className={classes.formControlLabel}
control={
<Switch
checked={this.state.fullWidth}
onChange={this.handleFullWidthChange}
value="fullWidth"
/>
}
label="Full width"
/>
</form>
</DialogContent>
<DialogActions>
<Button onClick={this.handleClose} color="primary">
Close
</Button>
</DialogActions>
</Dialog>
</React.Fragment>
);
}
}

(MaxWidthDialog as React.ComponentClass<MaxWidthDialogProps, MaxWidthDialogState>).propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(MaxWidthDialog);
5 changes: 4 additions & 1 deletion packages/material-ui/src/Select/SelectInput.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ export interface SelectInputProps {
name?: string;
native: boolean;
onBlur?: React.FocusEventHandler<any>;
onChange?: (event: React.ChangeEvent<HTMLSelectElement>, child: React.ReactNode) => void;
onChange?: (
event: React.ChangeEvent<{ name?: string; value: unknown }>,
child: React.ReactNode,
) => void;
onClose?: (event: React.ChangeEvent<{}>) => void;
onFocus?: React.FocusEventHandler<any>;
onOpen?: (event: React.ChangeEvent<{}>) => void;
Expand Down