-
-
Notifications
You must be signed in to change notification settings - Fork 1
Replace Radix UI dialog overlay with custom overlay to fix layout shift in VSCode webview #24
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,41 @@ function DialogOverlay({ | |
| ); | ||
| } | ||
|
|
||
| function CustomOverlay({ | ||
| className, | ||
| ...props | ||
| }: React.ComponentProps<"div">) { | ||
| React.useEffect(() => { | ||
| document.body.classList.add('dialog-open'); | ||
|
|
||
| return () => { | ||
| document.body.classList.remove('dialog-open'); | ||
| }; | ||
| }, []); | ||
|
Comment on lines
+51
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation for scroll locking by toggling the To fix this, you would need to track the number of active dialogs. A common approach is to use a module-level counter that is incremented when a dialog mounts and decremented when it unmounts. The class on If the application design guarantees that only one dialog can be open at any time, the current approach is acceptable, but it would be good practice to add a comment to the |
||
|
|
||
| return ( | ||
| <div | ||
| className={cn( | ||
| "absolute inset-0 z-50 bg-black/50", | ||
| className | ||
| )} | ||
| onClick={(e) => { | ||
| if (e.target === e.currentTarget) { | ||
| const escEvent = new KeyboardEvent('keydown', { | ||
| key: 'Escape', | ||
| code: 'Escape', | ||
| keyCode: 27, | ||
| which: 27, | ||
| bubbles: true | ||
| }); | ||
| document.dispatchEvent(escEvent); | ||
| } | ||
| }} | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| function DialogContent({ | ||
| className, | ||
| children, | ||
|
|
@@ -54,7 +89,7 @@ function DialogContent({ | |
| }) { | ||
| return ( | ||
| <DialogPortal data-slot="dialog-portal"> | ||
| <DialogOverlay /> | ||
| <CustomOverlay /> | ||
| <DialogPrimitive.Content | ||
| data-slot="dialog-content" | ||
| className={cn( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,3 +121,7 @@ | |
| @apply bg-background text-foreground; | ||
| } | ||
| } | ||
|
|
||
| body.dialog-open { | ||
| overflow: hidden !important; | ||
kubrickcode marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
+125
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using body.dialog-open {
/* Using !important is necessary to override VSCode webview styles and prevent layout shift. */
overflow: hidden !important;
} |
||
Uh oh!
There was an error while loading. Please reload this page.