Skip to content

Conversation

@Elm1992
Copy link
Contributor

@Elm1992 Elm1992 commented Nov 19, 2025

Description

modal 组件 centered为true时设置draggable无法拖拽

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

  • Improvements
    • Enhanced modal positioning and centering behavior when dragging
    • Improved fullscreen button styling with refined hover effects

@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

⚠️ No Changeset found

Latest commit: 432d8e7

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.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

Modified modal component and draggable utility to respect a centered state during drag operations. Transform calculations now conditionally apply centered translation (using calc(-50% + offset) math) when the modal is centered, with corresponding CSS class adjustments and reset behavior changes.

Changes

Cohort / File(s) Summary
Modal centering and dragging logic
packages/@core/ui-kit/popup-ui/src/modal/modal.vue, packages/@core/ui-kit/popup-ui/src/modal/use-modal-draggable.ts
Added shouldCentered computed property to modal.vue that combines centered and fullscreen states; updated transform calculation to use calc(-50% + offset) centering math; modified useModalDraggable signature with optional centered parameter; changed transform reset from 'none' to empty string; adjusted CSS border and centering classes.

Sequence Diagram(s)

sequenceDiagram
    participant Modal as modal.vue
    participant Composable as useModalDraggable
    
    Note over Modal,Composable: Initial Setup
    Modal->>Modal: Compute shouldCentered<br/>(centered && !fullscreen)
    Modal->>Composable: Pass centered ref
    
    Note over Modal,Composable: On Drag
    Composable->>Composable: Check centered.value
    alt Centered is true
        Composable->>Composable: Apply centered math<br/>translate(x, calc(-50% + y))
    else Centered is false
        Composable->>Composable: Apply direct translation<br/>translate(x, y)
    end
    Composable->>Modal: Update transform
    
    Note over Modal,Composable: On Reset
    Composable->>Composable: Clear transform<br/>(set to empty string)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Transform mathematics require verification (especially calc(-50% + offset) centering logic across drag and reopen scenarios)
  • Parameter signature change to useModalDraggable needs validation that all call sites are compatible
  • CSS class binding adjustments and their interaction with fullscreen state need visual verification

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • anncwb
  • vince292007
  • mynetfan

Poem

🐰 A modal finds its center, dragging smooth and bright,
With calculated offsets, positioned just right,
No longer lost in fullscreen's sprawling embrace,
Our modal now knows its proper place! ✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ⚠️ Warning PR description is incomplete; it lacks detailed explanation in English and has unchecked critical checklist items including tests, changelog, and documentation requirements. Add detailed description of the bug and fix in English, check off completed checklist items (tests run, changelog updated, self-review done), and verify all quality standards have been met.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the specific bug being fixed: when centered is true, the draggable modal cannot be dragged. It accurately summarizes the main change.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@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

🧹 Nitpick comments (2)
packages/@core/ui-kit/popup-ui/src/modal/use-modal-draggable.ts (1)

17-18: Center-aware transform logic looks correct; consider de‑duplicating the transform expression

The new optional centered flag and the branch between:

  • translate(${moveX}px, calc(-50% + ${moveY}px)) when centered
  • translate(${moveX}px, ${moveY}px) otherwise

are consistent with the goal of preserving the -50% baseline while still applying the drag offset, and remain backward compatible for call sites that don’t pass centered.

However, the same transform shape is now also constructed in modal.vue when reopening the dialog, which means any future tweak (e.g., adding scale, adjusting axis) must be changed in two places. Consider extracting a small helper (even just a local function in this module that modal.vue can reuse) to build the transform string from (x, y, isCentered) to keep the behavior in one place.

Also applies to: 76-82

packages/@core/ui-kit/popup-ui/src/modal/modal.vue (1)

107-109: Centering + draggable wiring is coherent; watch for runtime centered toggles and minor duplication

The introduction of:

  • shouldCentered = computed(() => centered.value && !shouldFullscreen.value)
  • passing shouldCentered into useModalDraggable
  • and using the same centered vs non-centered transform when reopening:
dialogRef.value.style.transform = shouldCentered.value
  ? `translate(${offsetX}px, calc(-50% + ${offsetY}px))`
  : `translate(${offsetX}px, ${offsetY}px)`;

lines up well with the hook changes and should fix the “centered + draggable” issue.

A couple of follow‑ups you may want to consider:

  1. Runtime centered changes while open
    The watch is keyed only on state?.value?.isOpen, so if centered is toggled while the modal is already open, the classes (top-1/2 vs not) will update, but the inline style.transform won’t be recomputed. If centered is intended to be a static configuration per modal, this is fine; if it’s expected to be toggled at runtime, you may want a small watch on shouldCentered (or a watchEffect that also depends on it) to recompute the transform or call resetPosition.

  2. Avoiding small duplications

    • The condition 'top-1/2': centered && !shouldFullscreen is logically equivalent to shouldCentered, so you could reference shouldCentered directly to keep the condition centralized.
    • The centered/non-centered transform expression is now duplicated here and in use-modal-draggable.ts; a tiny shared helper (e.g., getModalTransform(offsetX, offsetY, isCentered)) would keep these in sync.

These are refinements; core behavior looks sound.

Also applies to: 117-123, 140-143, 245-252

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f09aace and 432d8e7.

📒 Files selected for processing (2)
  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue (5 hunks)
  • packages/@core/ui-kit/popup-ui/src/modal/use-modal-draggable.ts (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-01-15T04:29:13.944Z
Learnt from: mynetfan
Repo: vbenjs/vue-vben-admin PR: 5397
File: playground/src/bootstrap.ts:23-30
Timestamp: 2025-01-15T04:29:13.944Z
Learning: In the Vue-Vben-Admin project, commented code in bootstrap.ts showing modal and drawer configuration examples should be preserved as reference documentation, even after moving to CSS variables for z-index management.

Applied to files:

  • packages/@core/ui-kit/popup-ui/src/modal/modal.vue
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: Check (windows-latest)
  • GitHub Check: Check (ubuntu-latest)
  • GitHub Check: Test (windows-latest)
  • GitHub Check: post-update (ubuntu-latest)
  • GitHub Check: post-update (windows-latest)
🔇 Additional comments (2)
packages/@core/ui-kit/popup-ui/src/modal/use-modal-draggable.ts (1)

109-116: Resetting transform with empty string is appropriate here

Changing resetPosition to set target.style.transform = '' (instead of forcing 'none') resets the inline transform while allowing any CSS class–driven transform (e.g., centering from the base DialogContent styles) to take effect again. This aligns with the centered/drag behavior introduced in this PR and avoids clobbering the component’s default transform.

No further changes needed in this block.

packages/@core/ui-kit/popup-ui/src/modal/modal.vue (1)

245-247: Styling tweaks for border and fullscreen button look safe

  • Changing 'border-border border' to 'border border-border' is effectively cosmetic for Tailwind and shouldn’t alter behavior.
  • The updated VbenIconButton classes (more explicit text color, hover background/text, opacity transition, and focus outline handling) are consistent with the rest of the UI kit and improve visual/interaction feedback without affecting logic.

No issues spotted here.

Also applies to: 321-326

@jinmao88 jinmao88 merged commit b6edc5f into vbenjs:main Nov 24, 2025
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants