mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-03 08:19:37 +08:00
6776bb8916
* docs: update demo * chore: add script * test: fix demo test * docs: convert demos * chore: move script * test: remove react-dom import * chore: update deps * docs: update riddle js * test: fix image test * docs: fix riddle demo
64 lines
1.7 KiB
Markdown
64 lines
1.7 KiB
Markdown
---
|
|
order: 3.1
|
|
title:
|
|
zh-CN: 必选样式
|
|
en-US: Required style
|
|
---
|
|
|
|
## zh-CN
|
|
|
|
通过 `requiredMark` 切换必选与可选样式。
|
|
|
|
## en-US
|
|
|
|
Switch required or optional style with `requiredMark`.
|
|
|
|
```tsx
|
|
import React, { useState } from 'react';
|
|
import { Form, Input, Button, Radio } from 'antd';
|
|
import { InfoCircleOutlined } from '@ant-design/icons';
|
|
|
|
type RequiredMark = boolean | 'optional';
|
|
|
|
const FormLayoutDemo = () => {
|
|
const [form] = Form.useForm();
|
|
const [requiredMark, setRequiredMarkType] = useState<RequiredMark>('optional');
|
|
|
|
const onRequiredTypeChange = ({ requiredMarkValue }: { requiredMarkValue: RequiredMark }) => {
|
|
setRequiredMarkType(requiredMarkValue);
|
|
};
|
|
|
|
return (
|
|
<Form
|
|
form={form}
|
|
layout="vertical"
|
|
initialValues={{ requiredMarkValue: requiredMark }}
|
|
onValuesChange={onRequiredTypeChange}
|
|
requiredMark={requiredMark}
|
|
>
|
|
<Form.Item label="Required Mark" name="requiredMarkValue">
|
|
<Radio.Group>
|
|
<Radio.Button value="optional">Optional</Radio.Button>
|
|
<Radio.Button value>Required</Radio.Button>
|
|
<Radio.Button value={false}>Hidden</Radio.Button>
|
|
</Radio.Group>
|
|
</Form.Item>
|
|
<Form.Item label="Field A" required tooltip="This is a required field">
|
|
<Input placeholder="input placeholder" />
|
|
</Form.Item>
|
|
<Form.Item
|
|
label="Field B"
|
|
tooltip={{ title: 'Tooltip with customize icon', icon: <InfoCircleOutlined /> }}
|
|
>
|
|
<Input placeholder="input placeholder" />
|
|
</Form.Item>
|
|
<Form.Item>
|
|
<Button type="primary">Submit</Button>
|
|
</Form.Item>
|
|
</Form>
|
|
);
|
|
};
|
|
|
|
export default () => <FormLayoutDemo />;
|
|
```
|