From 0d187111cbb59e9d32ede663c396571fe4cd5947 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 20 Apr 2023 18:49:21 +0800 Subject: [PATCH] fix: fix requiredMark hidden (#3796) --- packages/antd/docs/components/FormItem.md | 21 +++++++++++++++++++ .../antd/docs/components/FormItem.zh-CN.md | 21 +++++++++++++++++++ packages/antd/src/form-item/index.tsx | 7 ++++++- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/packages/antd/docs/components/FormItem.md b/packages/antd/docs/components/FormItem.md index 62e9fc1eaeb..7e3e326fe59 100644 --- a/packages/antd/docs/components/FormItem.md +++ b/packages/antd/docs/components/FormItem.md @@ -421,6 +421,27 @@ export default () => { x-decorator="FormItem" x-component="Input" /> + + + diff --git a/packages/antd/docs/components/FormItem.zh-CN.md b/packages/antd/docs/components/FormItem.zh-CN.md index 26e8c26da70..989211ed5bb 100644 --- a/packages/antd/docs/components/FormItem.zh-CN.md +++ b/packages/antd/docs/components/FormItem.zh-CN.md @@ -422,6 +422,27 @@ export default () => { x-decorator="FormItem" x-component="Input" /> + + + diff --git a/packages/antd/src/form-item/index.tsx b/packages/antd/src/form-item/index.tsx index 50973b094df..fe81f08ffb8 100644 --- a/packages/antd/src/form-item/index.tsx +++ b/packages/antd/src/form-item/index.tsx @@ -45,6 +45,7 @@ export interface IFormItemProps { enableOutlineFeedback?: boolean getPopupContainer?: (node: HTMLElement) => HTMLElement asterisk?: boolean + optionalMarkHidden?: boolean gridSpan?: number bordered?: boolean } @@ -76,6 +77,7 @@ const useFormItemLayout = (props: IFormItemProps) => { inset: props.inset ?? layout.inset, asterisk: props.asterisk, requiredMark: layout.requiredMark, + optionalMarkHidden: props.optionalMarkHidden, bordered: props.bordered ?? layout.bordered, feedbackIcon: props.feedbackIcon, feedbackLayout: props.feedbackLayout ?? layout.feedbackLayout ?? 'loose', @@ -144,6 +146,7 @@ export const BaseItem: React.FC> = ({ addonAfter, asterisk, requiredMark = true, + optionalMarkHidden = false, feedbackStatus, extra, feedbackText, @@ -235,7 +238,7 @@ export const BaseItem: React.FC> = ({ {'*'} )} - {!asterisk && requiredMark === 'optional' && ( + {!asterisk && requiredMark === 'optional' && !optionalMarkHidden && ( {locale?.Form?.optional} @@ -429,6 +432,8 @@ export const FormItem: ComposeFormItem = connect( feedbackStatus: takeFeedbackStatus(), feedbackText: takeMessage(), asterisk: takeAsterisk(), + optionalMarkHidden: + field.pattern === 'readPretty' && !('asterisk' in props), extra: props.extra || field.description, } })