Pull Request Number: 4272 Title: fix(checkbox, radio, select): missing data pressed attribute due to labelProps Base Branch: canary Head Branch: fix/selection-components-data-pressed Author: Peterl561 URL: https://github.com/nextui-org/nextui/pull/4272 State: CLOSED Created At: 2024-12-07T23:03:02Z Merged At: None Participants: Peterl561 Description: Closes #4260 📝 Description affects Checkbox, Radio, and Switch focus visible state should not be applied on pointer click missing data-pressed attribute before.mp4 🚀 New behavior affects Checkbox, Radio, and Switch fixes focus visible state on pointer click fixes data-pressed not being applied after.mp4 💣 Is this a breaking change (Yes/No): No 📝 Additional Information caused by #4220 affects Checkbox, Radio, and Switch components occurs when parent container is focusable (see sandbox) the aforementioned PR removed pressProps returned by usePress from getBaseProps this led to 2 issues removed onMouseDown handlers from base component, which was calling e.preventDefault() caused data-pressed attribute to no longer be applied to fix this, we can use labelProps from the affected components' respective hooks to replace the removed pressProps this works because labelProps is actually just pressProps from the usePress called internally in react-aria's component hooks it also does not regress the previous issue (#4210) addressed in the causative PR Commits: - fix(checkbox): missing data-pressed attribute due to labelProps\n- fix(radio): missing data-pressed attribute due to labelProps\n- fix(switch): missing data-pressed attribute due to labelProps\n Labels: Comments: - changeset-bot: ### ⚠️ No Changeset found Latest commit: 1f1e5069e9c9fbcd12353354c9194eea94f80576 Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**
This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/main/docs/adding-a-changeset.md). [Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/Peterl561/nextui/new/fix/selection-components-data-pressed?filename=.changeset/odd-donkeys-matter.md&value=---%0A%22%40nextui-org%2Fcheckbox%22%3A%20patch%0A%22%40nextui-org%2Fradio%22%3A%20patch%0A%22%40nextui-org%2Fswitch%22%3A%20patch%0A---%0A%0Afix(checkbox%2C%20radio%2C%20select)%3A%20missing%20data%20pressed%20attribute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mVkIjowLCJ1bnJlc29sdmVkIjowLCJ0b3RhbCI6MCwibGluayI6Im5leHR1aS1kb2NzLXYyLWdpdC1mb3JrLXBldGVybDU2MS1maXgtc2VsZWN0aS1mYWFiZDEtbmV4dHVpLW9yZy52ZXJjZWwuYXBwIn19XX0= **The latest updates on your projects**. Learn more about [Vercel for Git ↗︎](https://vercel.link/github-learn-more) | Name | Status | Preview | Comments | Updated (UTC) | | :--- | :----- | :------ | :------- | :------ | | **nextui-docs-v2** | ✅ Ready ([Inspect](https://vercel.com/nextui-org/nextui-docs-v2/2Uw9pcubVmwYMPwrndN9xBoCwCqX)) | [Visit Preview](https://nextui-docs-v2-git-fork-peterl561-fix-selecti-faabd1-nextui-org.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/nextui-docs-v2-git-fork-peterl561-fix-selecti-faabd1-nextui-org.vercel.app?via=pr-comment-feedback-link) | Dec 7, 2024 11:08pm | | **nextui-storybook-v2** | ✅ Ready ([Inspect](https://vercel.com/nextui-org/nextui-storybook-v2/GnvgZcYK4KSTQkGD4Pj2RZjhCZNg)) | [Visit Preview](https://nextui-storybook-v2-git-fork-peterl561-fix-se-3fc05a-nextui-org.vercel.app) | 💬 [**Add feedback**](https://vercel.live/open-feedback/nextui-storybook-v2-git-fork-peterl561-fix-se-3fc05a-nextui-org.vercel.app?via=pr-comment-feedback-link) | Dec 7, 2024 11:08pm | \n- vercel: @Peterl561 is attempting to deploy a commit to the **NextUI Inc** Team on [Vercel](https://vercel.com). A member of the Team first needs to [authorize it](https://vercel.com/git/authorize?team=NextUI%20Inc&type=github&job=%7B%22headInfo%22%3A%7B%22sha%22%3A%221f1e5069e9c9fbcd12353354c9194eea94f80576%22%7D%2C%22id%22%3A%22QmVL9CtxqZo42XfVup5jeZtT5uYjZEtY8iPEzd9pegMtjF%22%2C%22org%22%3A%22nextui-org%22%2C%22prId%22%3A4272%2C%22repo%22%3A%22nextui%22%7D). \n- coderabbitai: > [!IMPORTANT] > ## Review skipped > > Draft detected. > > Please check the settings in the CodeRabbit UI or the `.coderabbit.yaml` file in this repository. To trigger a single review, invoke the `@coderabbitai review` command. > > You can disable this status message by setting the `reviews.review_status` to `false` in the CodeRabbit configuration file. --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
\n- Peterl561: Working on tests\n- Peterl561: The hidden input in selection components fails to get click events due to logic in `usePress`.\n Files Changed: - packages/components/checkbox/src/use-checkbox.ts (modified, 3 changes)\n Patch: @@ -195,6 +195,7 @@ export function useCheckbox(props: UseCheckboxProps = {}) { const { inputProps, + labelProps, isSelected, isDisabled, isReadOnly, @@ -277,7 +278,7 @@ export function useCheckbox(props: UseCheckboxProps = {}) { "data-readonly": dataAttr(inputProps.readOnly), "data-focus-visible": dataAttr(isFocusVisible), "data-indeterminate": dataAttr(isIndeterminate), - ...mergeProps(hoverProps, otherProps), + ...mergeProps(hoverProps, labelProps, otherProps), }; }, [ slots,\n- packages/components/radio/src/use-radio.ts (modified, 4 changes)\n Patch: @@ -115,7 +115,7 @@ export function useRadio(props: UseRadioProps) { descriptionId, ]); - const {inputProps, isDisabled, isSelected, isPressed} = useReactAriaRadio( + const {inputProps, labelProps, isDisabled, isSelected, isPressed} = useReactAriaRadio( { value, children: typeof children === "function" ? true : children, @@ -166,7 +166,7 @@ export function useRadio(props: UseRadioProps) { "data-hover-unselected": dataAttr(isHovered && !isSelected), "data-readonly": dataAttr(inputProps.readOnly), "aria-required": dataAttr(isRequired), - ...mergeProps(hoverProps, otherProps), + ...mergeProps(hoverProps, labelProps, otherProps), }; }, [\n- packages/components/switch/src/use-switch.ts (modified, 8 changes)\n Patch: @@ -155,7 +155,11 @@ export function useSwitch(originalProps: UseSwitchProps = {}) { state.setSelected(isInputRefChecked); }, [inputRef.current]); - const {inputProps, isPressed, isReadOnly} = useReactAriaSwitch(ariaSwitchProps, state, inputRef); + const {inputProps, labelProps, isPressed, isReadOnly} = useReactAriaSwitch( + ariaSwitchProps, + state, + inputRef, + ); const {focusProps, isFocused, isFocusVisible} = useFocusRing({autoFocus: inputProps.autoFocus}); const {hoverProps, isHovered} = useHover({ isDisabled: inputProps.disabled, @@ -180,7 +184,7 @@ export function useSwitch(originalProps: UseSwitchProps = {}) { const getBaseProps: PropGetter = (props) => { return { - ...mergeProps(hoverProps, otherProps, props), + ...mergeProps(hoverProps, labelProps, otherProps, props), ref: domRef, className: slots.base({class: clsx(baseStyles, props?.className)}), "data-disabled": dataAttr(isDisabled),\n