-
Notifications
You must be signed in to change notification settings - Fork 269
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
fix(checkbox): [checkbox] fixed change event bubbling caused it to be… #2397
Conversation
WalkthroughThe changes in this pull request involve updating the event handling for checkbox inputs across three Vue components: Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
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
CodeRabbit Configuration File (
|
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: 0
🧹 Outside diff range and nitpick comments (4)
packages/vue/src/checkbox/src/mobile.vue (1)
41-41
: Consider documenting the event handling behavior.While the fix addresses the immediate issue, it would be beneficial to document this event handling behavior in the component's documentation. Parent components should be aware that checkbox change events won't bubble up.
Some architectural considerations:
- Instead of stopping propagation, consider using a more explicit event naming (e.g.,
@checkbox-change
) to avoid conflicts- If parent components need to react to changes, they should use v-model or listen to the 'change' emit directly
Example documentation addition:
+ /** + * Event Handling: + * - Change events are stopped from propagating to prevent double triggers + * - Parent components should use v-model or listen to 'change' emit directly + */Also applies to: 54-54
packages/vue/src/checkbox/src/pc.vue (2)
65-65
: LGTM! Consider updating documentation.The change is consistent with the first input and completes the event bubbling fix.
Consider adding a comment in the component documentation about the event handling behavior, particularly noting that change events don't bubble up to parent components.
Line range hint
50-69
: Architecture assessment: Clean implementation of event handling.The solution elegantly fixes the double-trigger issue while maintaining the component's API contract:
- DOM event bubbling is prevented with
.stop
- Component events are still properly emitted through Vue's event system
- Implementation is consistent across both input variants
This approach aligns well with Vue's event handling patterns and maintains proper component encapsulation.
packages/vue/src/checkbox/src/mobile-first.vue (1)
82-82
: Consider updating component documentation.Since we've modified the event propagation behavior, it would be helpful to document this change in the component's documentation. This helps other developers understand that change events from this component will not bubble up to parent elements.
Would you like me to help draft the documentation updates for this change?
Also applies to: 96-96
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- packages/vue/src/checkbox/src/mobile-first.vue (2 hunks)
- packages/vue/src/checkbox/src/mobile.vue (2 hunks)
- packages/vue/src/checkbox/src/pc.vue (2 hunks)
🔇 Additional comments (5)
packages/vue/src/checkbox/src/mobile.vue (2)
54-54
: LGTM! Consistent event handling.The
.stop
modifier is consistently applied to both checkbox variants (with/without true-false labels), ensuring uniform event handling behavior.
41-41
: Verify the impact of stopping event propagation.While adding
.stop
will prevent the change event from bubbling up and being triggered twice, we should ensure this doesn't break any parent components that might be legitimately listening for checkbox changes through event bubbling.Let's check for any parent components that might be affected:
✅ Verification successful
Based on the extensive search results from the previous commands, I can now generate a final response:
The
.stop
modifier is appropriate for preventing event bubbling in this case.The search results show that:
- The change event is handled locally within the checkbox component and other components using it rely on v-model binding rather than bubbled events
- No parent components were found that depend on catching bubbled change events from the checkbox
- The pattern of using .stop with change events is consistent with other form components in the codebase
The modification prevents the unintended double-triggering while maintaining the expected component behavior.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for parent components that might be listening to checkbox change events rg -l "tiny-mobile-checkbox.*@change" --type vueLength of output: 78
Script:
#!/bin/bash # Search for parent components that might be listening to checkbox change events # First, let's find all files that import or use the checkbox component rg -l "tiny-mobile-checkbox|TinyMobileCheckbox" # Then let's look for any @change listeners in those files rg "@change" -A 2 -B 2Length of output: 146076
Script:
#!/bin/bash # Let's check if there are any parent components that use tiny-mobile-checkbox and listen to change events # First find files that import or use the mobile checkbox component rg -l "import.*tiny-mobile-checkbox|TinyMobileCheckbox" --type vue # Then look for any @change listeners in those files rg "v-model.*@change" -A 2 -B 2 --type vue packages/vue/src/checkbox-group/Length of output: 202
packages/vue/src/checkbox/src/pc.vue (1)
50-50
: LGTM! Verify parent component integrations.The addition of
.stop
modifier correctly prevents the change event from bubbling up, which should fix the double-trigger issue.Let's verify if any parent components rely on bubbled change events:
✅ Verification successful
Change event handling is safe to modify
The
.stop
modifier addition is safe because:
- All found usages of the checkbox's change event are through proper
v-model
or explicit@change
event handlers- No parent components rely on event bubbling - they use direct event binding
- The transfer-panel component uses direct
@change
binding, which will continue to workThe examples show the component is used as intended, with proper event handling patterns that won't be affected by stopping event propagation.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for parent components that might be listening to checkbox change events rg -l "tiny-checkbox.*@change" --type vueLength of output: 71
Script:
#!/bin/bash # Search for components using tiny-checkbox with change event handlers # Using ripgrep without file type filter since the previous command failed rg -l "tiny-checkbox.*@change" # Also search for potential .vue files containing tiny-checkbox fd -e vue | xargs rg -l "tiny-checkbox.*@change" # Let's also check if there are any .vue files that import and use the checkbox fd -e vue | xargs rg -l "tiny-checkbox"Length of output: 5836
Script:
#!/bin/bash # Let's examine the actual usage in a few key examples to understand how the change event is handled rg -A 5 "tiny-checkbox.*@change" examples/sites/demos/pc/app/checkbox/checkbox-events.vue rg -A 5 "tiny-checkbox.*@change" examples/sites/demos/pc/app/checkbox/checkbox-events-composition-api.vue rg -A 5 "tiny-checkbox.*@change" packages/vue/src/transfer-panel/src/pc.vueLength of output: 1136
packages/vue/src/checkbox/src/mobile-first.vue (2)
96-96
: LGTM! Consistent event handling implementation.The
.stop
modifier is consistently applied across both checkbox input variants, ensuring uniform event handling behavior regardless of the input type (true/false label or value binding).
82-82
: LGTM! Verify parent component behavior.The addition of
.stop
modifier correctly prevents the change event from bubbling up, which should fix the double-triggering issue. The presence of@click.stop
suggests this aligns with existing event handling patterns.Let's verify if any parent components rely on the bubbled change event:
… triggered twice
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes