Skip to content

Commit

Permalink
fix: fix requiredMark hidden (#3796)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex authored Apr 20, 2023
1 parent 39fac2b commit 0d18711
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/antd/docs/components/FormItem.md
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,27 @@ export default () => {
x-decorator="FormItem"
x-component="Input"
/>
<SchemaField.String
default="When the field is not editable, always hide the required/optional flag"
x-editable={false}
x-decorator="FormItem"
x-component="Input"
/>
<SchemaField.String
title="I am Required"
required
default="Not editable"
x-editable={false}
x-decorator="FormItem"
x-component="Input"
/>
<SchemaField.String
title="I am Optional"
default="Not editable"
x-editable={false}
x-decorator="FormItem"
x-component="Input"
/>
</SchemaField>
</FormLayout>
</FormProvider>
Expand Down
21 changes: 21 additions & 0 deletions packages/antd/docs/components/FormItem.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,27 @@ export default () => {
x-decorator="FormItem"
x-component="Input"
/>
<SchemaField.String
default="字段不可编辑时,始终隐藏必填/选填标识"
x-editable={false}
x-decorator="FormItem"
x-component="Input"
/>
<SchemaField.String
title="我是必填项"
required
default="不可编辑"
x-editable={false}
x-decorator="FormItem"
x-component="Input"
/>
<SchemaField.String
title="我是选填项"
default="不可编辑"
x-editable={false}
x-decorator="FormItem"
x-component="Input"
/>
</SchemaField>
</FormLayout>
</FormProvider>
Expand Down
7 changes: 6 additions & 1 deletion packages/antd/src/form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface IFormItemProps {
enableOutlineFeedback?: boolean
getPopupContainer?: (node: HTMLElement) => HTMLElement
asterisk?: boolean
optionalMarkHidden?: boolean
gridSpan?: number
bordered?: boolean
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -144,6 +146,7 @@ export const BaseItem: React.FC<React.PropsWithChildren<IFormItemProps>> = ({
addonAfter,
asterisk,
requiredMark = true,
optionalMarkHidden = false,
feedbackStatus,
extra,
feedbackText,
Expand Down Expand Up @@ -235,7 +238,7 @@ export const BaseItem: React.FC<React.PropsWithChildren<IFormItemProps>> = ({
<span className={`${prefixCls}-asterisk`}>{'*'}</span>
)}
<label>{label}</label>
{!asterisk && requiredMark === 'optional' && (
{!asterisk && requiredMark === 'optional' && !optionalMarkHidden && (
<span className={`${prefixCls}-optional`}>
{locale?.Form?.optional}
</span>
Expand Down Expand Up @@ -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,
}
})
Expand Down

0 comments on commit 0d18711

Please sign in to comment.