mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(radio): remove required attribute for Radio with validationBehavior="aria" (#3110)
This commit is contained in:
parent
9a2cf47a60
commit
41d2eeb20b
5
.changeset/sour-starfishes-lick.md
Normal file
5
.changeset/sour-starfishes-lick.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@nextui-org/radio": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Remove required attribute for Radio with validationBehavior="aria"
|
||||||
@ -144,7 +144,7 @@ describe("Radio", () => {
|
|||||||
expect(onFocus).toBeCalled();
|
expect(onFocus).toBeCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work correctly with "isRequired" prop', () => {
|
it("should have required attribute when isRequired with native validationBehavior", () => {
|
||||||
const {getByRole, getAllByRole} = render(
|
const {getByRole, getAllByRole} = render(
|
||||||
<RadioGroup isRequired label="Options" validationBehavior="native">
|
<RadioGroup isRequired label="Options" validationBehavior="native">
|
||||||
<Radio value="1">Option 1</Radio>
|
<Radio value="1">Option 1</Radio>
|
||||||
@ -161,6 +161,23 @@ describe("Radio", () => {
|
|||||||
expect(radios[0]).toHaveAttribute("required");
|
expect(radios[0]).toHaveAttribute("required");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("should not have required attribute when isRequired with aria validationBehavior", () => {
|
||||||
|
const {getByRole, getAllByRole} = render(
|
||||||
|
<RadioGroup isRequired label="Options" validationBehavior="aria">
|
||||||
|
<Radio value="1">Option 1</Radio>
|
||||||
|
<Radio value="2">Option 2</Radio>
|
||||||
|
</RadioGroup>,
|
||||||
|
);
|
||||||
|
|
||||||
|
const group = getByRole("radiogroup");
|
||||||
|
|
||||||
|
expect(group).toHaveAttribute("aria-required", "true");
|
||||||
|
|
||||||
|
const radios = getAllByRole("radio");
|
||||||
|
|
||||||
|
expect(radios[0]).not.toHaveAttribute("required");
|
||||||
|
});
|
||||||
|
|
||||||
it("should work correctly with controlled value", () => {
|
it("should work correctly with controlled value", () => {
|
||||||
const onValueChange = jest.fn();
|
const onValueChange = jest.fn();
|
||||||
|
|
||||||
|
|||||||
@ -219,11 +219,11 @@ export function useRadio(props: UseRadioProps) {
|
|||||||
(props = {}) => {
|
(props = {}) => {
|
||||||
return {
|
return {
|
||||||
ref: inputRef,
|
ref: inputRef,
|
||||||
...mergeProps(props, inputProps, focusProps, {required: isRequired}),
|
...mergeProps(props, inputProps, focusProps),
|
||||||
onChange: chain(inputProps.onChange, onChange),
|
onChange: chain(inputProps.onChange, onChange),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
[inputProps, focusProps, isRequired, onChange],
|
[inputProps, focusProps, onChange],
|
||||||
);
|
);
|
||||||
|
|
||||||
const getLabelProps: PropGetter = useCallback(
|
const getLabelProps: PropGetter = useCallback(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user