Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(antd): Fix requiredmark hidden #3796

Merged
merged 2 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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