2019-07-03 20:14:39 +08:00
|
|
|
---
|
|
|
|
order: 3
|
|
|
|
title:
|
|
|
|
zh-CN: 表单布局
|
|
|
|
en-US: Form Layout
|
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
表单有三种布局。
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
There are three layout for form: `horizontal`, `vertical`, `inline`.
|
|
|
|
|
|
|
|
```tsx
|
|
|
|
import { Form, Input, Button, Radio } from 'antd';
|
|
|
|
|
|
|
|
const FormLayoutDemo = () => {
|
2019-12-30 14:53:47 +08:00
|
|
|
const [form] = Form.useForm();
|
2019-07-03 20:14:39 +08:00
|
|
|
const [formLayout, setFormLayout] = React.useState('horizontal');
|
|
|
|
|
2019-12-30 14:53:47 +08:00
|
|
|
const onFormLayoutChange = ({ layout }) => {
|
|
|
|
setFormLayout(layout);
|
2019-07-03 20:14:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const formItemLayout =
|
|
|
|
formLayout === 'horizontal'
|
|
|
|
? {
|
|
|
|
labelCol: { span: 4 },
|
|
|
|
wrapperCol: { span: 14 },
|
|
|
|
}
|
|
|
|
: null;
|
2019-12-30 14:53:47 +08:00
|
|
|
|
2019-07-03 20:14:39 +08:00
|
|
|
const buttonItemLayout =
|
|
|
|
formLayout === 'horizontal'
|
|
|
|
? {
|
|
|
|
wrapperCol: { span: 14, offset: 4 },
|
|
|
|
}
|
|
|
|
: null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
2019-12-30 14:53:47 +08:00
|
|
|
<Form
|
|
|
|
{...formItemLayout}
|
|
|
|
layout={formLayout}
|
|
|
|
form={form}
|
|
|
|
initialValues={{ layout: formLayout }}
|
|
|
|
onValuesChange={onFormLayoutChange}
|
|
|
|
>
|
|
|
|
<Form.Item label="Form Layout" name="layout">
|
|
|
|
<Radio.Group value={formLayout}>
|
2019-07-03 20:14:39 +08:00
|
|
|
<Radio.Button value="horizontal">Horizontal</Radio.Button>
|
|
|
|
<Radio.Button value="vertical">Vertical</Radio.Button>
|
|
|
|
<Radio.Button value="inline">Inline</Radio.Button>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
2019-12-30 14:53:47 +08:00
|
|
|
<Form.Item label="Field A">
|
2019-07-03 20:14:39 +08:00
|
|
|
<Input placeholder="input placeholder" />
|
|
|
|
</Form.Item>
|
2019-12-30 14:53:47 +08:00
|
|
|
<Form.Item label="Field B">
|
2019-07-03 20:14:39 +08:00
|
|
|
<Input placeholder="input placeholder" />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item {...buttonItemLayout}>
|
|
|
|
<Button type="primary">Submit</Button>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
ReactDOM.render(<FormLayoutDemo />, mountNode);
|
|
|
|
```
|