From 9458dbc8df8e6aa59636efd3974801819dc712d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=9F=A1=E9=9F=AC?= Date: Thu, 7 Apr 2022 15:24:22 +0800 Subject: [PATCH 1/2] fix(antd): fix form tab type check issue --- packages/antd/src/form-tab/index.tsx | 92 ++++++++++++++-------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/packages/antd/src/form-tab/index.tsx b/packages/antd/src/form-tab/index.tsx index 2c1ae750f1d..81350e62173 100644 --- a/packages/antd/src/form-tab/index.tsx +++ b/packages/antd/src/form-tab/index.tsx @@ -25,8 +25,8 @@ export interface IFormTabPaneProps extends TabPaneProps { } type ComposedFormTab = React.FC & { - TabPane?: React.FC - createFormTab?: (defaultActiveKey?: string) => IFormTab + TabPane: React.FC + createFormTab: (defaultActiveKey?: string) => IFormTab } const useTabs = () => { @@ -60,52 +60,54 @@ const createFormTab = (defaultActiveKey?: string) => { return markRaw(formTab) } -export const FormTab: ComposedFormTab = observer(({ formTab, ...props }) => { - const field = useField() - const tabs = useTabs() - const _formTab = useMemo(() => { - return formTab ? formTab : createFormTab() - }, []) - const prefixCls = usePrefixCls('formily-tab', props) - const activeKey = props.activeKey || _formTab?.activeKey +export const FormTab: ComposedFormTab = observer( + ({ formTab, ...props }: IFormTabProps) => { + const field = useField() + const tabs = useTabs() + const _formTab = useMemo(() => { + return formTab ? formTab : createFormTab() + }, []) + const prefixCls = usePrefixCls('formily-tab', props) + const activeKey = props.activeKey || _formTab?.activeKey - const badgedTab = (key: SchemaKey, props: any) => { - const errors = field.form.queryFeedbacks({ - type: 'error', - address: `${field.address.concat(key)}.*`, - }) - if (errors.length) { - return ( - - {props.tab} - - ) + const badgedTab = (key: SchemaKey, props: any) => { + const errors = field.form.queryFeedbacks({ + type: 'error', + address: `${field.address.concat(key)}.*`, + }) + if (errors.length) { + return ( + + {props.tab} + + ) + } + return props.tab } - return props.tab + return ( + { + props.onChange?.(key) + formTab?.setActiveKey?.(key) + }} + > + {tabs.map(({ props, schema, name }, key) => ( + + + + ))} + + ) } - return ( - { - props.onChange?.(key) - formTab?.setActiveKey?.(key) - }} - > - {tabs.map(({ props, schema, name }, key) => ( - - - - ))} - - ) -}) +) as unknown as ComposedFormTab const TabPane: React.FC = ({ children }) => { return {children} From 915da3582ef508288220eb1cf50636d37de66f79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E9=9F=A1=E9=9F=AC?= Date: Thu, 7 Apr 2022 19:16:30 +0800 Subject: [PATCH 2/2] fix(next): fix form tab type check issue --- packages/next/src/form-tab/index.tsx | 86 ++++++++++++++-------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/packages/next/src/form-tab/index.tsx b/packages/next/src/form-tab/index.tsx index 648023ce306..5b5fa63fac3 100644 --- a/packages/next/src/form-tab/index.tsx +++ b/packages/next/src/form-tab/index.tsx @@ -29,8 +29,8 @@ export interface IFormTabPaneProps extends TabPaneProps { } type ComposedFormTab = React.FC & { - TabPane?: React.FC - createFormTab?: (defaultActiveKey?: React.ReactText) => IFormTab + TabPane: React.FC + createFormTab: (defaultActiveKey?: React.ReactText) => IFormTab } const useTabs = () => { @@ -64,49 +64,51 @@ const createFormTab = (defaultActiveKey?: string) => { return markRaw(formTab) } -export const FormTab: ComposedFormTab = observer(({ formTab, ...props }) => { - const field = useField() - const tabs = useTabs() - const _formTab = useMemo(() => { - return formTab ? formTab : createFormTab() - }, []) - const prefixCls = usePrefixCls('formily-tab', props) - const activeKey = props.activeKey || _formTab?.activeKey +export const FormTab: ComposedFormTab = observer( + ({ formTab, ...props }: IFormTabProps) => { + const field = useField() + const tabs = useTabs() + const _formTab = useMemo(() => { + return formTab ? formTab : createFormTab() + }, []) + const prefixCls = usePrefixCls('formily-tab', props) + const activeKey = props.activeKey || _formTab?.activeKey - const badgedTab = (key: SchemaKey, props: any) => { - const errors = field.form.queryFeedbacks({ - type: 'error', - address: `${field.address.concat(key)}.*`, - }) - if (errors.length) { - return ( - - {props.tab} - - ) + const badgedTab = (key: SchemaKey, props: any) => { + const errors = field.form.queryFeedbacks({ + type: 'error', + address: `${field.address.concat(key)}.*`, + }) + if (errors.length) { + return ( + + {props.tab} + + ) + } + return props.tab } - return props.tab - } - return ( - { - props.onChange?.(key) - formTab?.setActiveKey?.(key) - }} - lazyLoad={false} - > - {tabs.map(({ props, schema, name }, key) => ( - - - - ))} - - ) -}) + return ( + { + props.onChange?.(key) + formTab?.setActiveKey?.(key) + }} + lazyLoad={false} + > + {tabs.map(({ props, schema, name }, key) => ( + + + + ))} + + ) + } +) as unknown as ComposedFormTab const TabPane: React.FC = ({ children }) => { return {children}