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:
@linhf2023 2023-12-07 11:22:31 +08:00 committed by GitHub
parent d0cc4087dd
commit cca77e61b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 13 deletions

View File

@ -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]);

View File

@ -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', () => {