2020-06-05 18:06:52 +08:00
|
|
|
|
---
|
|
|
|
|
order: 999999
|
|
|
|
|
title:
|
|
|
|
|
zh-CN: 引用字段
|
|
|
|
|
en-US: Ref item
|
|
|
|
|
debug: true
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
|
|
|
|
|
请优先使用 `ref`!
|
|
|
|
|
|
|
|
|
|
## en-US
|
|
|
|
|
|
|
|
|
|
Use `ref` first!
|
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
|
```tsx
|
|
|
|
|
import type { InputRef } from 'antd';
|
2020-06-05 18:06:52 +08:00
|
|
|
|
import { Button, Form, Input } from 'antd';
|
2022-05-23 14:37:16 +08:00
|
|
|
|
import React from 'react';
|
2020-06-05 18:06:52 +08:00
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
|
const App: React.FC = () => {
|
2020-06-05 18:06:52 +08:00
|
|
|
|
const [form] = Form.useForm();
|
2022-05-19 09:46:26 +08:00
|
|
|
|
const ref = React.useRef<InputRef>(null);
|
2020-06-05 18:06:52 +08:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Form form={form} initialValues={{ list: ['light'] }}>
|
|
|
|
|
<Form.Item name="test" label="test">
|
|
|
|
|
<Input ref={ref} />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
|
|
|
|
|
<Form.List name="list">
|
|
|
|
|
{fields =>
|
|
|
|
|
fields.map(field => (
|
2022-05-19 09:46:26 +08:00
|
|
|
|
<Form.Item {...field} key={field.key}>
|
2020-06-05 18:06:52 +08:00
|
|
|
|
<Input ref={ref} />
|
|
|
|
|
</Form.Item>
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
</Form.List>
|
|
|
|
|
|
|
|
|
|
<Button
|
2022-05-19 09:46:26 +08:00
|
|
|
|
htmlType="button"
|
2020-06-05 18:06:52 +08:00
|
|
|
|
onClick={() => {
|
|
|
|
|
form.getFieldInstance('test').focus();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Focus Form.Item
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={() => {
|
|
|
|
|
form.getFieldInstance(['list', 0]).focus();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Focus Form.List
|
|
|
|
|
</Button>
|
|
|
|
|
</Form>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
|
export default App;
|
2020-06-05 18:06:52 +08:00
|
|
|
|
```
|