-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
chore: Add checkbox-as-button
example
#1002
Conversation
…lled checkbox example
This pull request is being automatically deployed with Vercel (learn more). reakit – ./🔍 Inspect: https://vercel.com/ariakit/reakit/72HfEkMsJmCKRuyNQrCpP4zbiMiz [Deployment for 8257cff canceled] ariakit – ./🔍 Inspect: https://vercel.com/ariakit/ariakit/DAV946Hwuexyo4N4qMe3Dvor1ZNu |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Codecov Report
@@ Coverage Diff @@
## main #1002 +/- ##
==========================================
+ Coverage 67.96% 69.29% +1.33%
==========================================
Files 177 180 +3
Lines 4367 4410 +43
Branches 1195 1209 +14
==========================================
+ Hits 2968 3056 +88
+ Misses 1398 1353 -45
Partials 1 1
Continue to review full report at Codecov.
|
Thank you @SCasarotto! I think this is actually a good example of A I'm thinking about something like this: const checkbox = useCheckboxState();
const [focusVisible, setFocusVisible] = useState(false);
return (
<label className="label">
<VisuallyHidden>
<Checkbox
state={checkbox}
onFocusVisible={() => setFocusVisible(true)}
onBlur={() => setFocusVisible(false)}
/>
</VisuallyHidden>
<div
className="checkbox"
data-focus-visible={focusVisible ? "" : undefined}
data-checked={checkbox.value}
/>
I have read and agree to the terms and conditions
</label>
); |
packages/ariakit/src/checkbox/__examples__/checkbox-as-button/style.css
Outdated
Show resolved
Hide resolved
packages/ariakit/src/checkbox/__examples__/checkbox-as-button/test.tsx
Outdated
Show resolved
Hide resolved
@diegohaz Thanks for the feedback. 🙏 I will probably migrate this over to fill the |
@diegohaz I figured I would keep this PR for the |
… space interactions, removed the user of tailwinds content
We should always recommend a native checkbox (even if it's visually hidden) if the element is used within a form or is styled similarly to a native checkbox (which is the case here). A checkbox as a button shouldn't look like a checkbox. It could be a button with a checkmark, a menu item checkbox, or something else. If we're already rendering a visually hidden native checkbox, we don't need another checkbox. In my example, the native checkbox will receive focus and the |
packages/ariakit/src/checkbox/__examples__/checkbox-as-button/index.tsx
Outdated
Show resolved
Hide resolved
packages/ariakit/src/checkbox/__examples__/checkbox-as-button/test.tsx
Outdated
Show resolved
Hide resolved
packages/ariakit/src/checkbox/__examples__/checkbox-as-button/test.tsx
Outdated
Show resolved
Hide resolved
I think I updated all of those things. |
packages/ariakit/src/checkbox/__examples__/checkbox-as-button/index.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thank you @SCasarotto! ❤️
Checkbox
as button examplecheckbox-as-button
example
Thanks a lot for contributing! Based on our community guidelines, every person who has a PR of any kind merged is offered an invitation to the Reakit organization. Should you accept, you'll get write access to the main repository and a fancy Reakit logo on your GitHub profile. You'll be able to label and close issues, create new branches etc. Make sure to read our contribution and community guidelines, which explains all of this in more detail. If you have any questions, let me know! |
This update adds a
as button
example for theCheckbox
component:Screenshots
How to test?
Run
yarn dev
Visit http://localhost:3000/examples/checkbox-as-button.
Does this PR introduce breaking changes?
Nope, just an example
PS: This is my first PR here so I am unable to update #939 and am looking for constructive feedback. I have some spare time and wanted to contribute where I can. If I get the flow for these examples I can probably tackle a bunch of them.