mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-28 05:05:48 +08:00
chore: Form.Item should not support requiredMark (#41725)
* test: add case * chore: Form.Item does not support requiredMark
This commit is contained in:
parent
6761292bbd
commit
0e65dad8e9
@ -186,8 +186,8 @@ export default function ItemHolder(props: ItemHolderProps) {
|
||||
{/* Label */}
|
||||
<FormItemLabel
|
||||
htmlFor={fieldId}
|
||||
requiredMark={requiredMark}
|
||||
{...props}
|
||||
requiredMark={requiredMark}
|
||||
required={required ?? isRequired}
|
||||
prefixCls={prefixCls}
|
||||
/>
|
||||
|
@ -51,7 +51,7 @@ const MemoInput = React.memo(
|
||||
);
|
||||
|
||||
export interface FormItemProps<Values = any>
|
||||
extends FormItemLabelProps,
|
||||
extends Omit<FormItemLabelProps, 'requiredMark'>,
|
||||
FormItemInputProps,
|
||||
RcFieldProps<Values> {
|
||||
prefixCls?: string;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user