From 7d63d7d53d6f32ebec0f7fcb4274e5ddaa3d799f Mon Sep 17 00:00:00 2001 From: dengfuping Date: Fri, 8 Dec 2023 09:21:11 +0800 Subject: [PATCH] fix(design): Form hideRequiredMark should be priority over ConfigProvider form.requiredMark --- .../__snapshots__/index.test.tsx.snap | 86 +++++++++++++++++++ .../design/src/form/__tests__/index.test.tsx | 13 +++ .../design/src/form/demo/hideRequiredMark.tsx | 47 ++++++++++ .../form/demo/requiredMark-same-with-antd.tsx | 49 +++++++++++ packages/design/src/form/index.md | 4 + packages/design/src/form/index.tsx | 12 ++- .../__tests__/__snapshots__/demo.test.ts.snap | 30 +++++-- 7 files changed, 230 insertions(+), 11 deletions(-) create mode 100644 packages/design/src/form/demo/hideRequiredMark.tsx create mode 100644 packages/design/src/form/demo/requiredMark-same-with-antd.tsx diff --git a/packages/design/src/form/__tests__/__snapshots__/index.test.tsx.snap b/packages/design/src/form/__tests__/__snapshots__/index.test.tsx.snap index dbaace938..0a9f79483 100644 --- a/packages/design/src/form/__tests__/__snapshots__/index.test.tsx.snap +++ b/packages/design/src/form/__tests__/__snapshots__/index.test.tsx.snap @@ -1,5 +1,91 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Drawer Form hideRequiredMark should be priority over ConfigProvider form.requiredMark 1`] = ` +
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+
+
+
+
+
+
+`; + exports[`Drawer requiredMark could be changed 1`] = `
{ expect(container.querySelector('.ant-form-item-optional')).toBeFalsy(); expect(asFragment().firstChild).toMatchSnapshot(); }); + + it('Form hideRequiredMark should be priority over ConfigProvider form.requiredMark', () => { + const { container, asFragment } = render( + + + + ); + expect(asFragment().firstChild).toMatchSnapshot(); + }); }); diff --git a/packages/design/src/form/demo/hideRequiredMark.tsx b/packages/design/src/form/demo/hideRequiredMark.tsx new file mode 100644 index 000000000..927702e82 --- /dev/null +++ b/packages/design/src/form/demo/hideRequiredMark.tsx @@ -0,0 +1,47 @@ +import { Button, ConfigProvider, Form, Input, message } from '@oceanbase/design'; +import React from 'react'; + +const onFinish = (values: any) => { + message.success('Success'); + console.log(values); +}; + +const onFinishFailed = (errorInfo: any) => { + message.error('Failed'); + console.log(errorInfo); +}; + +const App: React.FC = () => ( + + + + + + + + + + + + +
+); + +export default App; diff --git a/packages/design/src/form/demo/requiredMark-same-with-antd.tsx b/packages/design/src/form/demo/requiredMark-same-with-antd.tsx new file mode 100644 index 000000000..52d1097f5 --- /dev/null +++ b/packages/design/src/form/demo/requiredMark-same-with-antd.tsx @@ -0,0 +1,49 @@ +import { Button, ConfigProvider, Form, Input, message } from '@oceanbase/design'; +import React from 'react'; + +const onFinish = (values: any) => { + message.success('Success'); + console.log(values); +}; + +const onFinishFailed = (errorInfo: any) => { + message.error('Failed'); + console.log(errorInfo); +}; + +const App: React.FC = () => ( + +
+ + + + + + + + + +
+
+); + +export default App; diff --git a/packages/design/src/form/index.md b/packages/design/src/form/index.md index 4ae995e65..b00fd1ba2 100644 --- a/packages/design/src/form/index.md +++ b/packages/design/src/form/index.md @@ -14,6 +14,10 @@ nav: + + + + ## API diff --git a/packages/design/src/form/index.tsx b/packages/design/src/form/index.tsx index 67afcf19a..b7aa388aa 100644 --- a/packages/design/src/form/index.tsx +++ b/packages/design/src/form/index.tsx @@ -20,15 +20,21 @@ type CompoundedComponent = React.FC & { create: typeof AntForm.create; }; -const Form: CompoundedComponent = props => { +const Form: CompoundedComponent = ({ hideRequiredMark, ...restProps }) => { const { form: contextForm } = useContext(ConfigProvider.ConfigContext); return ( // @ts-ignore to ignore children type error ); }; diff --git a/tests/__tests__/__snapshots__/demo.test.ts.snap b/tests/__tests__/__snapshots__/demo.test.ts.snap index cb0e651bf..dfdd34653 100644 --- a/tests/__tests__/__snapshots__/demo.test.ts.snap +++ b/tests/__tests__/__snapshots__/demo.test.ts.snap @@ -624,6 +624,20 @@ exports[`renders packages/design/src/form/demo/form-item-tooltip.tsx correctly 1 } `; +exports[`renders packages/design/src/form/demo/hideRequiredMark.tsx correctly 1`] = ` +{ + "html": "
", + "type": "demo", +} +`; + +exports[`renders packages/design/src/form/demo/requiredMark-same-with-antd.tsx correctly 1`] = ` +{ + "html": "
", + "type": "demo", +} +`; + exports[`renders packages/design/src/input-number/demo/addon.tsx correctly 1`] = ` { "html": "
+
$
+
$
cascader
", @@ -1392,56 +1406,56 @@ exports[`renders packages/ui/src/IconFont/demo/basic.tsx correctly 1`] = ` exports[`renders packages/ui/src/Login/demo/activate.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/authCode.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/basic.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/bg-image.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/board.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/is-mobile.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/otherLogin.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `; exports[`renders packages/ui/src/Login/demo/with-alert.tsx correctly 1`] = ` { - "html": "
", + "html": "
", "type": "demo", } `;