-
Notifications
You must be signed in to change notification settings - Fork 28
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
chore: use radix to improve modal component #854
base: next
Are you sure you want to change the base?
chore: use radix to improve modal component #854
Conversation
721a7c1
to
8765327
Compare
Thanks. Your changes looks good to me. For handling animation Radix seems using data attributes. Here is an example from Shadcn doing samething on top of Radix. Please take a look at the approach and see is there anyway to remove our js approach to handle animations. |
Please check my latest changes. I used data attributes to handle animations. |
In this commit I tried to prevent an error related to |
1fa28fb
to
4d55b42
Compare
… handle error for custom header
@@ -179,6 +179,10 @@ export const Content = styled('div', { | |||
overflowX: 'hidden', | |||
}); | |||
|
|||
export const DialogTitle = styled(Dialog.DialogTitle, { | |||
margin: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will affect a11y and they did the trick for that. We can ignore 1px difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was not added to handle 1px difference. Actually with position set to absolute
, there is no 1px difference. When we wrap title
with Dialog.DialogTitle
it will be wrapped in a h2
element which have a default margin so I added this to remove the unwanted margin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
Since we've opened this PR some time ago, please make sure the dependencies are in their latest version.
// Restrict the overlay click area to just the overlay element, rather than the entire page | ||
const handleOverlayClick: MouseEventHandler = (event) => { | ||
if (event.target === overlayRef.current) { | ||
handleBackDropClick(!open); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleBackDropClick
is only used here, so you can remove the function and move its code block to here.
|
||
if (event.target === event.currentTarget && dismissible) { | ||
// The escape key functionality only works when the focus is within the overlay (modal). | ||
const handleScapeKeyDown = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const handleScapeKeyDown = () => { | |
const handleEscapeKeyDown = () => { |
<Dialog.Portal container={container}> | ||
<DialogOverlay ref={overlayRef} onClick={handleOverlayClick}> | ||
<DialogContent | ||
onClick={handleContentClick} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of hacking with onClick
and :focus
, you can consider using onInteractOutside
.
ref
It will be like:
onInteractOutside={handleOverlayClick}
Ensure renaming the function and also remove the onClick
s.
Summary
Use Radix UI to improve modal component.
In result of this change:
Fixes # 1777
Notes:
Currently, we are handling the logic related to showing animation on opening and closing modal and positioning the content of modal based on
anchor
prop. Before exploring the Radix UI document, we were optimistic about that it can handle these animation logics and positioning the content of modal, but after checking the documentation I didn't find such solutions so I kept it as it is.How did you test this change?
Tested this change by checking most of modals.
Checklist: