-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
refactor: button & card ripple #4284
Conversation
🦋 Changeset detectedLatest commit: dce6aca The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@sudongyuer is attempting to deploy a commit to the NextUI Inc Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThis pull request introduces a patch for the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
packages/components/button/src/use-button.ts (1)
152-153
: Consider adding JSDoc deprecation notice for onClickWhile the code handles both event types correctly, adding a formal deprecation notice would help guide users towards using
onPress
.{ elementType: as, isDisabled, + /** @deprecated Use onPress instead of onClick */ onClick: onClick, onPress: chain(onPress, handlePress), ...otherProps, }
packages/components/card/src/use-card.ts (1)
111-111
: Consider adding type safety for onClick deprecationTo maintain consistency with the button component, consider adding similar onClick deprecation handling.
{ + /** @deprecated Use onPress instead of onClick */ onClick: onClick, onPress: chain(onPress, handlePress), elementType: as, isDisabled: !originalProps.isPressable, allowTextSelectionOnPress, ...otherProps, }
Also applies to: 114-114
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (4)
.changeset/rude-cobras-grab.md
(1 hunks)packages/components/button/src/use-button.ts
(2 hunks)packages/components/card/src/use-card.ts
(3 hunks)packages/components/ripple/src/use-ripple.ts
(3 hunks)
✅ Files skipped from review due to trivial changes (1)
- .changeset/rude-cobras-grab.md
🔇 Additional comments (2)
packages/components/button/src/use-button.ts (1)
138-138
: LGTM! Clean transition to PressEvent handling
The implementation correctly handles both the new onPress
and deprecated onClick
events, maintaining backward compatibility while moving towards the more accessible PressEvent pattern.
Also applies to: 140-145
packages/components/card/src/use-card.ts (1)
99-99
: LGTM! Consistent implementation with button component
The card component's press handling implementation correctly mirrors the button component's approach, ensuring consistent behavior across components.
Also applies to: 101-107
const onPress = useCallback((event: PressEvent) => { | ||
const trigger = event.target; |
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.
Consider using event.currentTarget instead of event.target
Using event.target
might lead to incorrect ripple positioning when clicking on child elements within the button/card. The target
could be a nested element, while currentTarget
always refers to the element the event handler is attached to.
- const trigger = event.target;
+ const trigger = event.currentTarget;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const onPress = useCallback((event: PressEvent) => { | |
const trigger = event.target; | |
const onPress = useCallback((event: PressEvent) => { | |
const trigger = event.currentTarget; |
x: event.x - size / 2, | ||
y: event.y - size / 2, |
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.
💡 Codebase verification
Scroll position needs to be accounted for in ripple coordinates
The current implementation uses event.x
and event.y
which are viewport-relative coordinates. This will cause misaligned ripples when the page is scrolled since these coordinates don't account for scroll position. The suggested fix in the review comment using event.pageX
, event.pageY
and getBoundingClientRect()
is the correct approach as it properly handles scroll position.
packages/components/ripple/src/use-ripple.ts
: Replace viewport coordinates with page-relative coordinates that account for scroll position and element position.
🔗 Analysis chain
Verify scroll position handling in coordinate calculation
The direct use of event.x
and event.y
might not account for scroll position, potentially causing misaligned ripples when the page is scrolled.
- x: event.x - size / 2,
- y: event.y - size / 2,
+ x: event.pageX - trigger.getBoundingClientRect().left - size / 2,
+ y: event.pageY - trigger.getBoundingClientRect().top - size / 2,
Let me gather more context about the ripple implementation to verify the coordinate calculation.
Let me try a different approach to examine the ripple implementation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for scroll position handling in ripple implementations
rg -A 5 "scroll(Left|Top)"
ast-grep --pattern 'event.x'
Length of output: 2846
Script:
#!/bin/bash
# Check the complete ripple implementation and event handling
ast-grep --pattern 'function useRipple' -A 30
rg -l "getBoundingClientRect|pageX|pageY" packages/components/ripple/
Length of output: 119
Script:
#!/bin/bash
# Check the complete ripple implementation file content
cat packages/components/ripple/src/use-ripple.ts
# Also check for any test files that might show the expected behavior
fd -e test.ts -e test.tsx -e spec.ts -e spec.tsx ripple packages/components/
Length of output: 1169
The PR fixes the ripple issue on touch devices, which we saw after upgrading the RA. |
Closes #
📝 Description
Refactor Button & Card ripple
In the latest version of react-aria they added the pointer events to the usePress hook so we no longer need to hack this in the components that use ripple
https://react-spectrum.adobe.com/react-aria/examples/ripple-button.html
⛳️ Current behavior (updates)
🚀 New behavior
2024-12-09.03.00.23.mov
💣 Is this a breaking change (Yes/No):
📝 Additional Information
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Documentation