From f5e0408649de722557b8685f57b1ace914a00cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=9E=AB?= <7971419+crazyair@users.noreply.github.com> Date: Thu, 30 Nov 2023 17:34:50 +0800 Subject: [PATCH] feat: support selector (#46180) * feat: support selector * fix: ts text * feat: md * feat: snap --- .../form/__tests__/__snapshots__/demo-extend.test.ts.snap | 3 +++ components/form/__tests__/__snapshots__/demo.test.tsx.snap | 3 +++ components/form/demo/useWatch.tsx | 3 +++ components/form/index.en-US.md | 4 +++- components/form/index.zh-CN.md | 4 +++- package.json | 2 +- 6 files changed, 16 insertions(+), 3 deletions(-) diff --git a/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap b/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap index a2cd43e046..3593baf2b4 100644 --- a/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap +++ b/components/form/__tests__/__snapshots__/demo-extend.test.ts.snap @@ -19514,6 +19514,9 @@ Array [
Name Value:+
+ Custom Value: name: +, ] `; diff --git a/components/form/__tests__/__snapshots__/demo.test.tsx.snap b/components/form/__tests__/__snapshots__/demo.test.tsx.snap index 8938d79790..293fe3eda8 100644 --- a/components/form/__tests__/__snapshots__/demo.test.tsx.snap +++ b/components/form/__tests__/__snapshots__/demo.test.tsx.snap @@ -8256,6 +8256,9 @@ Array [
Name Value:+
+ Custom Value: +, ] `; diff --git a/components/form/demo/useWatch.tsx b/components/form/demo/useWatch.tsx index 068d5e6180..50932710cd 100644 --- a/components/form/demo/useWatch.tsx +++ b/components/form/demo/useWatch.tsx @@ -4,6 +4,8 @@ import { Form, Input, InputNumber, Typography } from 'antd'; const Demo: React.FC = () => { const [form] = Form.useForm<{ name: string; age: number }>(); const nameValue = Form.useWatch('name', form); + // The selector is static and does not support closures. + const customValue = Form.useWatch((values) => `name: ${values.name || ''}`, form); return ( <> @@ -18,6 +20,7 @@ const Demo: React.FC = () => {
Name Value: {nameValue}+
Custom Value: {customValue}