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
USWDS - Modal: Remove padding style rules after modal close #5493
Conversation
Flagging that we might have to update #5315 to include changes made by this PR |
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 was able to confirm the original issue is specific to StorybookJS and its known init issues.
How I confirmed
- Using StorybookJS: Confirming padding was reported as
0
initially. We callstart.js
in.storybook/preview.js
to initialize components. In this file we're checking for two DOM states; one for DOMReady and another for DOM already loaded [best practice outlined in Document: DOMContentLoaded event - Web APIs | MDN]. - USWDS Sandbox: Added padding and got the correct values on toggle.
It seems like a better experience to move the padding check closer to the modal toggle. Is it possible to handle padding when toggleModal()
is called?
packages/usa-modal/src/index.js
Outdated
@@ -49,7 +42,7 @@ const onMenuClose = () => { | |||
* @param {KeyboardEvent} event the keydown event | |||
* @returns {boolean} safeActive if mobile is open | |||
*/ | |||
function toggleModal(event) { | |||
function toggleModal(event, temporaryBodyPadding) { |
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 like the idea of improving the accuracy of the padding by checking on init, but we should check for padding inside of the toggle or at the top-level.
@mejiaj I moved the padding check to |
@mahoneycm Can you let me know if the component still behaves as expected, even if the actual padding values vary? |
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.
Values are differing for me but it IS working as expected!
- Initial padding matches up
- Opening the modal does not cause content shift
- Opening modal updates body's padding via inline styles
- Closing the modal reverts padding to initial state!
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.
Small question on the removal of all styles on body, otherwise 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.
Nice fix, thanks!
use similar treatment as uswds/uswds#5493
Summary
Updated how the modal JavaScript resets body padding. Now the component will rely on the CSS to reset the body padding rather than injecting an inline style with JavaScript.
Improved body padding detection in modal JavaScript. The JS now checks for body padding after the modal has been set up.
Breaking change
This is not a breaking change.
Related issue
Closes #5361
Related pull requests
Changelog PR
Preview link
Problem statement
When the modal opens, it adds a temporary padding to the body to account for the missing scrollbar. When the modal closes, it is expected that the padding resets to the body's initial padding definition. For example, the Storybook body has an initial padding value of
1rem
, and the expectation is that the body styles would return to1rem
when the modal is closed. However, in the current state in Storybook, the modal JS changes the body padding to0px
when the modal is closed.This appears to only happen in Storybook and could not be replicated in
uswds-sandbox
oruswds-site
. I believe it is related to how Storybook initializes.Solution
develop
, the component changes the body padding using the following methods:Testing and review
In Storybook:
In the sandbox demo or USWDS-site demo: