<フォーム>をダイアログに入れることができますが、actionsプロパティの代わりに{actions}をフォーム内に配置する必要があります。 Submitアクションボタンにはtype = "submit"が必要です(type = "reset"もサポートされています)。
jsFiddle:HTML5 form=""
属性でhttps://jsfiddle.net/14dugwp3/6/
const {
Dialog,
TextField,
FlatButton,
MuiThemeProvider,
getMuiTheme,
} = MaterialUI;
class Example extends React.Component {
constructor(props) {
super(props);
this.state = { open: true };
this.handleClose = this._handleClose.bind(this);
}
_handleClose() {
this.setState({ open: false });
}
render() {
const actions = [
<FlatButton
type="reset"
label="Reset"
secondary={true}
style={{ float: 'left' }}
/>,
<FlatButton
label="Cancel"
primary={true}
onClick={this.handleClose}
/>,
<FlatButton
type="submit"
label="Submit"
primary={true}
/>,
];
return (
<Dialog
title="Dialog With Custom Width"
modal={true}
open={this.state.open}
>
<form action="/" method="POST" onSubmit={(e) => { e.preventDefault(); alert('Submitted form!'); this.handleClose(); } }>
This dialog spans the entire width of the screen.
<TextField name="email" hintText="Email" />
<TextField name="pwd" type="password" hintText="Password" />
<div style={{ textAlign: 'right', padding: 8, margin: '24px -24px -24px -24px' }}>
{actions}
</div>
</form>
</Dialog>
);
}
}
const App =() => (
<MuiThemeProvider muiTheme={getMuiTheme() }>
<Example />
</MuiThemeProvider>
);
ReactDOM.render(
<App />,
document.getElementById('container')
);
フォームをコンポーネントにして状態そのものを持たせたいのであれば、reduxを使ってデータ状態を構築できますか? –
はい。コンポーネントは状態(オープン状態のような)を扱うことができます。あるいは、ステートレス関数にして、 "open"を小道具として渡すことができます(小道具はreduxで設定できます)。上記のコンポーネントはステートレス関数に変換されます。それをreduxのconnect()でラップして、店舗に配線することができます。 https://jsfiddle.net/b3ahf3se/2/幸運! –
私は自分のフォームを「」のように、コンポーネント「 」にしました。どのようにアクションをフォームに入れることができますか? –