mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-11-30 02:59:04 +08:00
fix(form): legacy hideRequiredMark
props priority (#46299)
* fix(form): Reduce global requireMark priority * chore: add test --------- Co-authored-by: linhf123 <wb-lhf780012@antgroup.com>
This commit is contained in:
parent
d0cc4087dd
commit
cca77e61b9
@ -88,13 +88,13 @@ const InternalForm: React.ForwardRefRenderFunction<FormInstance, FormProps> = (p
|
||||
return requiredMark;
|
||||
}
|
||||
|
||||
if (contextForm && contextForm.requiredMark !== undefined) {
|
||||
return contextForm.requiredMark;
|
||||
}
|
||||
|
||||
if (hideRequiredMark) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (contextForm && contextForm.requiredMark !== undefined) {
|
||||
return contextForm.requiredMark;
|
||||
}
|
||||
|
||||
return true;
|
||||
}, [hideRequiredMark, requiredMark, contextForm]);
|
||||
|
@ -1089,16 +1089,44 @@ describe('Form', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('legacy hideRequiredMark', () => {
|
||||
const { container } = render(
|
||||
<Form hideRequiredMark role="form">
|
||||
<Form.Item name="light" label="light" required>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Form>,
|
||||
);
|
||||
describe('legacy hideRequiredMark', () => {
|
||||
it('should work', () => {
|
||||
const { container } = render(
|
||||
<Form hideRequiredMark role="form">
|
||||
<Form.Item name="light" label="light" required>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Form>,
|
||||
);
|
||||
|
||||
expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark');
|
||||
expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark');
|
||||
});
|
||||
|
||||
it('priority should be higher than CP', () => {
|
||||
const { container, rerender } = render(
|
||||
<ConfigProvider form={{ requiredMark: true }}>
|
||||
<Form hideRequiredMark role="form">
|
||||
<Form.Item name="light" label="light" required>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</ConfigProvider>,
|
||||
);
|
||||
|
||||
expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark');
|
||||
|
||||
rerender(
|
||||
<ConfigProvider form={{ requiredMark: undefined }}>
|
||||
<Form hideRequiredMark role="form">
|
||||
<Form.Item name="light" label="light" required>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</ConfigProvider>,
|
||||
);
|
||||
|
||||
expect(container.querySelector('form')!).toHaveClass('ant-form-hide-required-mark');
|
||||
});
|
||||
});
|
||||
|
||||
it('form should support disabled', () => {
|
||||
|
Loading…
Reference in New Issue
Block a user