Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useCheckbox does not prevent form submittion is isRequired === true #7317

Open
mJarsater opened this issue Nov 5, 2024 · 1 comment
Open

Comments

@mJarsater
Copy link

mJarsater commented Nov 5, 2024

Provide a general summary of the issue here

When using the useCheckbox hook to contstruct a custom checkbox the isRequired prop does not prevent form submittions.

🤔 Expected Behavior?

The isRequired prop should work the same way when using the Checkbox component vs the useCheckbox hook.

😯 Current Behavior

It seems like it is getting the correct aria attribute: aria-required="true" but it does not prevent form sunmittions.

💁 Possible Solution

No response

🔦 Context

    "react-aria": "3.35.0",
    "react-aria-components": "1.4.0",
     "react-stately": "3.33.0",

🖥️ Steps to Reproduce

https://codesandbox.io/p/sandbox/fc6w74

Version

1.4.1

What browsers are you seeing the problem on?

Firefox, Chrome, Safari, Microsoft Edge

If other, please specify.

No response

What operating system are you using?

macOS 15.0.1 (24A348)

🧢 Your Company/Team

No response

🕷 Tracking Issue

No response

@nwidynski
Copy link
Contributor

@mJarsater Thanks for reporting this 👍

Afaik, React Aria Components do not aim to provide the same defaults as the hooks. You can achieve the same behavior with the hook by setting the validationBehavior property to native. This is done by default inside the <Checkbox />:

https://github.com/adobe/react-spectrum/blob/5ed06068ee2742f32e066ffa8eb55fd93a083123/packages/react-aria-components/src/Checkbox.tsx#L177C2-L177C91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants