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

fix(checkbox): [checkbox] fixed change event bubbling caused it to be… #2397

Merged
merged 1 commit into from
Oct 25, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Oct 25, 2024

… triggered twice

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Enhanced event handling for checkbox inputs across mobile and desktop components to prevent event propagation.
  • Bug Fixes

    • Improved control flow related to checkbox state changes, ensuring more predictable behavior for parent components.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request involve updating the event handling for checkbox inputs across three Vue components: mobile-first.vue, mobile.vue, and pc.vue. The @change event listeners have been modified to include the .stop modifier, which prevents the event from propagating up the DOM tree. This adjustment may impact how parent components respond to checkbox state changes, but no other significant alterations to the components' logic or structure were made.

Changes

File Path Change Summary
packages/vue/src/checkbox/src/... Updated @change event listeners to include .stop modifier for checkboxes.

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • kagol

Poem

In the meadow, bunnies hop,
Checkbox changes, never stop!
With .stop, events won't flee,
Parent watchers, wait and see!
Hopping forward, we embrace,
A smoother, happier checkbox space! 🐇✨


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the bug Something isn't working label Oct 25, 2024
Copy link

@coderabbitai coderabbitai bot left a 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:

  1. Instead of stopping propagation, consider using a more explicit event naming (e.g., @checkbox-change) to avoid conflicts
  2. 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:

  1. DOM event bubbling is prevented with .stop
  2. Component events are still properly emitted through Vue's event system
  3. 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

📥 Commits

Files that changed from the base of the PR and between d3c8944 and 0540231.

📒 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:

  1. The change event is handled locally within the checkbox component and other components using it rely on v-model binding rather than bubbled events
  2. No parent components were found that depend on catching bubbled change events from the checkbox
  3. 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 vue

Length 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 2

Length 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:

  1. All found usages of the checkbox's change event are through proper v-model or explicit @change event handlers
  2. No parent components rely on event bubbling - they use direct event binding
  3. The transfer-panel component uses direct @change binding, which will continue to work

The 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 vue

Length 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.vue

Length 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:

@zzcr zzcr merged commit e27f58d into dev Oct 25, 2024
6 of 7 checks passed
@kagol kagol deleted the fix-checkbox-pop-error-1025 branch November 4, 2024 06:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant