diff --git a/docs/src/pages/demos/dialogs/ConfirmationDialog.js b/docs/src/pages/demos/dialogs/ConfirmationDialog.js index 2cb29251c30738..d6a5f5cd88f3d1 100644 --- a/docs/src/pages/demos/dialogs/ConfirmationDialog.js +++ b/docs/src/pages/demos/dialogs/ConfirmationDialog.js @@ -31,31 +31,32 @@ const options = [ ]; function ConfirmationDialogRaw(props) { - const [value, setValue] = React.useState(props.value); + const { onClose, value: valueProp, ...other } = props; + const [value, setValue] = React.useState(valueProp); const radioGroupRef = React.useRef(null); - React.useEffect(() => { - setValue(props.value); - }, [props.value]); + if (valueProp !== value) { + setValue(valueProp); + } function handleEntering() { - radioGroupRef.current.focus(); + if (radioGroupRef.current != null) { + radioGroupRef.current.focus(); + } } function handleCancel() { - props.onClose(props.value); + onClose(value); } function handleOk() { - props.onClose(value); + onClose(value); } function handleChange(event, newValue) { setValue(newValue); } - const { value: valueProps, ...otherProps } = props; - return ( Phone Ringtone diff --git a/docs/src/pages/demos/dialogs/ConfirmationDialog.tsx b/docs/src/pages/demos/dialogs/ConfirmationDialog.tsx new file mode 100644 index 00000000000000..f7740c4259be22 --- /dev/null +++ b/docs/src/pages/demos/dialogs/ConfirmationDialog.tsx @@ -0,0 +1,165 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { makeStyles, Theme } from '@material-ui/core/styles'; +import Button from '@material-ui/core/Button'; +import List from '@material-ui/core/List'; +import ListItem from '@material-ui/core/ListItem'; +import ListItemText from '@material-ui/core/ListItemText'; +import DialogTitle from '@material-ui/core/DialogTitle'; +import DialogContent from '@material-ui/core/DialogContent'; +import DialogActions from '@material-ui/core/DialogActions'; +import Dialog from '@material-ui/core/Dialog'; +import RadioGroup from '@material-ui/core/RadioGroup'; +import Radio from '@material-ui/core/Radio'; +import FormControlLabel from '@material-ui/core/FormControlLabel'; + +const options = [ + 'None', + 'Atria', + 'Callisto', + 'Dione', + 'Ganymede', + 'Hangouts Call', + 'Luna', + 'Oberon', + 'Phobos', + 'Pyxis', + 'Sedna', + 'Titania', + 'Triton', + 'Umbriel', +]; + +export interface ConfirmationDialogRawProps { + classes: Record<'paper', 'string'>; + value: string; + open: boolean; + onClose: (value: string) => void; +} + +function ConfirmationDialogRaw(props: ConfirmationDialogRawProps) { + const { onClose, value: valueProp, ...other } = props; + const [value, setValue] = React.useState(valueProp); + const radioGroupRef = React.useRef(null); + + if (valueProp !== value) { + setValue(valueProp); + } + + function handleEntering() { + if (radioGroupRef.current != null) { + radioGroupRef.current.focus(); + } + } + + function handleCancel() { + onClose(value); + } + + function handleOk() { + onClose(value); + } + + function handleChange(event: React.ChangeEvent<{}>, newValue: string) { + setValue(newValue); + } + + return ( + + Phone Ringtone + + + {options.map(option => ( + } label={option} /> + ))} + + + + + + + + ); +} + +ConfirmationDialogRaw.propTypes = { + onClose: PropTypes.func, + value: PropTypes.string, +}; + +const useStyles = makeStyles((theme: Theme) => ({ + root: { + width: '100%', + maxWidth: 360, + backgroundColor: theme.palette.background.paper, + }, + paper: { + width: '80%', + maxHeight: 435, + }, +})); + +function ConfirmationDialog() { + const classes = useStyles(); + const [open, setOpen] = React.useState(false); + const [value, setValue] = React.useState('Dione'); + + function handleClickListItem() { + setOpen(true); + } + + function handleClose(newValue: string) { + setOpen(false); + setValue(newValue); + } + + return ( +
+ + + + + + + + + + + + +
+ ); +} + +export default ConfirmationDialog; diff --git a/packages/material-ui/src/DialogContent/DialogContent.d.ts b/packages/material-ui/src/DialogContent/DialogContent.d.ts index b824a3b49c1568..783821fc855f46 100644 --- a/packages/material-ui/src/DialogContent/DialogContent.d.ts +++ b/packages/material-ui/src/DialogContent/DialogContent.d.ts @@ -2,7 +2,9 @@ import * as React from 'react'; import { StandardProps } from '..'; export interface DialogContentProps - extends StandardProps, DialogContentClassKey> {} + extends StandardProps, DialogContentClassKey> { + dividers?: boolean; +} export type DialogContentClassKey = 'root';