Skip to content

Conversation

@gweesin
Copy link
Contributor

@gweesin gweesin commented Mar 9, 2025

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: #3079

What is the new behavior?

reactive when placement change

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced a dynamic configuration update that enables real-time modifications of popover options and placements.
    • Enhanced interactivity so that components now adjust their positioning responsively and react to manual triggers.
  • Tests

    • Expanded automated test coverage to validate responsive placement behavior and ensure proper cleanup during interactions.

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2025

Walkthrough

This pull request introduces a new setOptions method to the PopperJS class, enabling dynamic updates to its configuration by merging new options into its existing settings. In addition, it corrects a comment typo in the Vue popper implementation and adds a watcher for the props.placement property to update state and trigger placement updates with conditional manual event emission. The test suite for the Popover component is enhanced with cleanup logic and new tests verifying reactive changes to placement.

Changes

File(s) Change Summary
packages/utils/.../index.ts Added new method setOptions(options: PopperOptions) in the PopperJS class using Object.assign to merge new options with existing settings.
packages/vue-hooks/.../vue-popper.ts Corrected a typo in a comment ("doDestory" → "doDestroy") and introduced a watcher for props.placement that updates state.currentPlacement, calls popperJS.setOptions, triggers updatePopper, and emits an event if props.trigger is 'manual'.
packages/vue/.../popover.test.tsx Enhanced test suite by adding an afterEach cleanup hook, refactoring the wrapper variable, updating an existing placement test, and adding a new test for reactive placement changes in the Popover component.

Sequence Diagram(s)

sequenceDiagram
    participant Component as Vue Component
    participant Watcher as Placement Watcher
    participant PopperJS as PopperJS Instance
    participant EventBus as Event Emitter

    Component->>Watcher: Change props.placement
    Watcher->>Component: Update state.currentPlacement
    Watcher->>PopperJS: setOptions({ placement: newValue })
    alt props.trigger == 'manual'
        Watcher->>EventBus: Emit update event for model value
    end
    Watcher->>Component: nextTick -> updatePopper()
Loading

Possibly related PRs

Suggested labels

bug, enhancement

Suggested reviewers

  • zzcr

Poem

I'm a hoppy rabbit coding in the glen,
Merging options with a joyful pen.
Comments fixed and watchers in play,
Tests ensuring the code won't stray.
Leaping high for a bright new day! 🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/vue-hooks/src/vue-popper.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/utils/src/popper/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/vue/src/popover/__tests__/popover.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd468ac and 45d9b5a.

📒 Files selected for processing (3)
  • packages/utils/src/popper/index.ts (1 hunks)
  • packages/vue-hooks/src/vue-popper.ts (2 hunks)
  • packages/vue/src/popover/__tests__/popover.test.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (5)
packages/utils/src/popper/index.ts (1)

905-908: Effective implementation of setOptions method.

The addition of the setOptions method follows the standard Popper.js API and enables reactive updates to popover configuration after instantiation. The method correctly uses Object.assign to merge new options with existing ones.

This implementation is essential for making the popover placement reactive as intended in the PR and follows good practices by including a reference link to the official documentation.

packages/vue-hooks/src/vue-popper.ts (1)

239-253: Well-structured reactive placement implementation.

This new watcher correctly handles placement changes by:

  1. Updating the state.currentPlacement
  2. Using the newly added setOptions method
  3. Triggering updatePopper on nextTick for immediate visual updates
  4. Properly emitting events for manual trigger mode

The implementation respects the disabled state and ensures the UI updates consistently when placement changes, which properly addresses the issue mentioned in the PR objectives.

packages/vue/src/popover/__tests__/popover.test.tsx (3)

14-18: Good test hygiene with proper cleanup.

Adding the wrapper variable and afterEach hook for unmounting ensures that tests don't interfere with each other and prevents memory leaks. This is important for UI component tests where DOM elements might otherwise persist between test runs.


47-58: Test implementation for placement attribute.

Good implementation of the previously marked todo test. The test correctly verifies that the popover's x-placement attribute matches the specified placement prop after the trigger event.


60-75: Excellent reactive placement test.

This new test thoroughly validates the core functionality of this PR by:

  1. Creating a reactive placement ref
  2. Verifying initial placement rendering
  3. Updating the placement value
  4. Confirming that the DOM updates to reflect the new placement

This test is crucial for ensuring the reactive behavior works as expected and prevents regression in future changes.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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 Mar 9, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request addresses a bug in the popover component by making its placement reactive. It introduces a new method setOptions in the popper utility to update options dynamically and adds a watcher in the vue-popper to handle placement changes. Additionally, tests are added to ensure the reactivity of placement changes.

Changes

File Summary
packages/utils/src/popper/index.ts Added a setOptions method to update popper options dynamically.
packages/vue-hooks/src/vue-popper.ts Introduced a watcher to make popover placement reactive and handle placement changes.
packages/vue/src/popover/tests/popover.test.tsx Added tests to verify the reactivity of popover placement changes.

state.currentPlacement = val
state.popperJS?.setOptions({ placement: val })

if (props.disabled) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition props.disabled should be checked before setting state.currentPlacement and calling setOptions. This ensures that no unnecessary operations are performed when the popover is disabled.

@zzcr zzcr merged commit 9fc171a into opentiny:dev Mar 12, 2025
11 checks passed
@gweesin gweesin deleted the fix/popper-placement-reactive branch March 12, 2025 01:52
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.

3 participants