chore: Form.Item should not support requiredMark (#41725)

* test: add case

* chore: Form.Item does not support requiredMark
This commit is contained in:
Wuxh 2023-04-10 12:02:06 +08:00 committed by GitHub
parent 6761292bbd
commit 0e65dad8e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 2 deletions

View File

@ -186,8 +186,8 @@ export default function ItemHolder(props: ItemHolderProps) {
{/* Label */}
<FormItemLabel
htmlFor={fieldId}
requiredMark={requiredMark}
{...props}
requiredMark={requiredMark}
required={required ?? isRequired}
prefixCls={prefixCls}
/>

View File

@ -51,7 +51,7 @@ const MemoInput = React.memo(
);
export interface FormItemProps<Values = any>
extends FormItemLabelProps,
extends Omit<FormItemLabelProps, 'requiredMark'>,
FormItemInputProps,
RcFieldProps<Values> {
prefixCls?: string;

View File

@ -38,6 +38,9 @@ export interface FormItemLabelProps {
label?: React.ReactNode;
labelAlign?: FormLabelAlign;
labelCol?: ColProps;
/**
* @internal Used for pass `requiredMark` from `<Form />`
*/
requiredMark?: RequiredMark;
tooltip?: LabelTooltipType;
}

View File

@ -1797,4 +1797,29 @@ describe('Form', () => {
expect(onChange).toHaveBeenNthCalledWith(idx++, 'validating');
expect(onChange).toHaveBeenNthCalledWith(idx++, 'success');
});
// https://user-images.githubusercontent.com/32004925/230819163-464fe90d-422d-4a6d-9e35-44a25d4c64f1.png
it('should not render `requiredMark` when Form.Item has no required prop', () => {
// Escaping TypeScript error
const genProps = (value: any) => ({ ...value });
const { container } = render(
<Form name="basic" requiredMark="optional">
<Form.Item
label="First Name"
name="firstName"
required
{...genProps({ requiredMark: false })}
>
<Input />
</Form.Item>
<Form.Item label="Last Name" name="lastName" required {...genProps({ requiredMark: true })}>
<Input />
</Form.Item>
</Form>,
);
expect(container.querySelectorAll('.ant-form-item-required')).toHaveLength(2);
expect(container.querySelectorAll('.ant-form-item-required-mark-optional')).toHaveLength(2);
});
});