feat: Add center direction & unified transitions for true responsive dialogs#10
Open
weepaho3 wants to merge 5 commits intoborabaloglu:mainfrom
Open
feat: Add center direction & unified transitions for true responsive dialogs#10weepaho3 wants to merge 5 commits intoborabaloglu:mainfrom
center direction & unified transitions for true responsive dialogs#10weepaho3 wants to merge 5 commits intoborabaloglu:mainfrom
Conversation
Contributor
|
@weepaho3 is attempting to deploy a commit to the borabaloglu's projects Team on Vercel. A member of the Team first needs to authorize it. |
- Adjusted `onDrag` transform calculation to offset from 100% for left/top directions, ensuring correct relative movement. - Updated `resetDrawer` to reset to 100% translation for left/top directions so the drawer stays visible in the open state. - Corrected `swipeToClose` calculation in `onRelease` to account for the inverted coordinate system of left/top drawers (calculating distance from the open 100%fix(core): correct drag gestures for left and top directions - Adjusted `onDrag` transform calculation to offset from 100% for left/top directions, ensuring correct relative movement. - Updated `resetDrawer` to reset to 100% translation for left/top directions so the drawer stays visible in the open state. - Corrected `swipeToClose` calculation in `onRelease` to account for the inverted coordinate system of left/top drawers (calculating distance from the open 100% position).
Author
|
Sorry, I found some more bugs regarding drag behavior and animations, particularly for the top and left directions. I've fixed them now, so everything should be good to go. You can preview the changes here: https://vaul-base-www.vercel.app/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introducing a
centerdirection and refactors the CSS/JS positioning logic to enable smooth, morphing transitions between all drawer directions (e.g.,bottom<->center).This allows developers to create responsive dialogs that maintain state (like form inputs) when resizing the window, offering a significantly better UX than the current standard practice.
Problem
Currently, the standard approach for "Responsive Dialogs" (as seen in the shadcn/ui examples) relies on conditional rendering:
Issues with this approach:
Drawerunmounts and theDialogmounts. Any state (e.g., text typed into an<input>is lost.💡 The Solution
Since
vaulis built on top of Radix/Base UI Dialog primitives, we can handle the "Desktop Modal" state directly withinvaulby adding acenterdirection.By unifying the CSS
transformlogic for all directions, we can now simply change thedirectionprop dynamically:🛠️ Changes
1. Unified Coordinate System
Previously, different directions used different CSS properties (
top,bottom,left,right) which made CSS transitions between them impossible.I refactored
style.cssso that all directions (including the newcenter) use a unifiedtransform: translate3d(...)approach relative to consistent offsets (e.g.,50%).2.
centerDirectionAdded support for
direction="center". This mimics a standard modal dialog behavior but keeps thevaulcontext alive.3. Morphing vs. Entry Animation
Added a
data-vaul-drawer-morphingattribute.4. Drag Logic Update
Updated the JS drag calculations (
onDrag,resetDrawer) to respect the new CSS offsets, ensuring dragging works correctly.Demo
I have added an responsive example to the example page.