Skip to content

Commit

Permalink
docs: Fix Form provider demo (ant-design#44391)
Browse files Browse the repository at this point in the history
* docs: fix provider demo

* test: update snapshot
  • Loading branch information
zombieJ committed Aug 24, 2023
1 parent eaa8635 commit 0dd651c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
25 changes: 24 additions & 1 deletion components/form/__tests__/__snapshots__/demo-extend.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -6833,6 +6833,25 @@ exports[`renders components/form/demo/form-context.tsx extend context correctly
</div>
</div>
</div>
<div
class="ant-form-item ant-form-item-hidden"
>
<div
class="ant-row ant-form-item-row"
>
<div
class="ant-col ant-col-16 ant-form-item-control"
>
<div
class="ant-form-item-control-input"
>
<div
class="ant-form-item-control-input-content"
/>
</div>
</div>
</div>
</div>
<div
class="ant-form-item"
>
Expand Down Expand Up @@ -6928,7 +6947,11 @@ exports[`renders components/form/demo/form-context.tsx extend context correctly
</form>
`;

exports[`renders components/form/demo/form-context.tsx extend context correctly 2`] = `[]`;
exports[`renders components/form/demo/form-context.tsx extend context correctly 2`] = `
[
"Warning: [antd: Form.Item] \`name\` is only used for validate React element. If you are using Form.Item as layout display, please remove \`name\` instead.",
]
`;

exports[`renders components/form/demo/form-in-modal.tsx extend context correctly 1`] = `
<div>
Expand Down
19 changes: 19 additions & 0 deletions components/form/__tests__/__snapshots__/demo.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4025,6 +4025,25 @@ exports[`renders components/form/demo/form-context.tsx correctly 1`] = `
</div>
</div>
</div>
<div
class="ant-form-item ant-form-item-hidden"
>
<div
class="ant-row ant-form-item-row"
>
<div
class="ant-col ant-col-16 ant-form-item-control"
>
<div
class="ant-form-item-control-input"
>
<div
class="ant-form-item-control-input-content"
/>
</div>
</div>
</div>
</div>
<div
class="ant-form-item"
>
Expand Down
12 changes: 9 additions & 3 deletions components/form/demo/form-context.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from 'react';
import { SmileOutlined, UserOutlined } from '@ant-design/icons';
import { Avatar, Button, Form, Input, InputNumber, Modal, Typography } from 'antd';
import { Avatar, Button, Form, Input, InputNumber, Modal, Space, Typography } from 'antd';
import type { FormInstance } from 'antd/es/form';

const layout = {
Expand Down Expand Up @@ -93,6 +93,10 @@ const App: React.FC = () => {
<Form.Item name="group" label="Group Name" rules={[{ required: true }]}>
<Input />
</Form.Item>

{/* Create a hidden field to make Form instance record this */}
<Form.Item name="users" hidden />

<Form.Item
label="User List"
shouldUpdate={(prevValues, curValues) => prevValues.users !== curValues.users}
Expand All @@ -103,8 +107,10 @@ const App: React.FC = () => {
<ul>
{users.map((user) => (
<li key={user.name} className="user">
<Avatar icon={<UserOutlined />} />
{user.name} - {user.age}
<Space>
<Avatar icon={<UserOutlined />} />
{`${user.name} - ${user.age}`}
</Space>
</li>
))}
</ul>
Expand Down

0 comments on commit 0dd651c

Please sign in to comment.