Conversation
|
@mejiaj @amyleadem Bumping for review when you have the bandwidth! |
mejiaj
left a comment
There was a problem hiding this comment.
Good work here! I've added additional comments & suggestions below.
What I tested in sequential order:
- PR description: Is PR description accurate and clear. Added suggestion below.
- No Regressions: Have there been any regressions in visuals/functionality.
- New features: Removing
ID, aria-labelledby, and aria-describedbyfromusa-modaltriggers error in console. - Code: Does it meet USWDS code standards for formatting and code style.
PR description
The items I tested related to process. Added suggestions below.
What I tested:
- Changelog PR exists & is linked.
- Preview link exists & is accurate.
- Testing & Review is clear & reflect changes.
⚠️ This is a complex PR, so we could improve clarity by adding a new list that has expectations.
Suggestions for Testing & Review section:
### Review
1. Steps.
2. To.
3. Review.
### Testing
- [ ] No visual or functional regressions to modal.
- [ ] Component uses behavior pattern.
- [ ] Removing `ID, aria-labelledby, and aria-describedby` from `usa-modal` triggers error in console.
- [ ] Repo instructions ― I haven't gone through these steps.Note
This would just be a new section that only highlights expectations for this work to be considered "done."
Code
In general, please be sure to add JSDoc comments to functions.
| ) { | ||
| const attribute = modalContent.attributes[attributeIndex]; | ||
|
|
||
| modalAttributes.forEach((attribute) => { |
packages/usa-modal/src/index.js
Outdated
| modalWrapper.appendChild(modalContent); | ||
| modalContent.parentNode.insertBefore(overlayDiv, modalContent); | ||
| overlayDiv.appendChild(modalContent); | ||
| const setModalAttributes = (baseComponent, targetWrapper) => { |
There was a problem hiding this comment.
- Can we add a JSDoc comment to this and any new functions?
- Does
targetWrappermean the modal content wrapper?
There was a problem hiding this comment.
Resolved in 0e34893
and yes! targetWrapper is the wrapper made for the individual modal component on init
There was a problem hiding this comment.
Would it make sense to rename targetWrapper to something more descriptive like modalContentWrapper?
There was a problem hiding this comment.
I think this adds clarity! I'll add it
packages/usa-modal/src/index.js
Outdated
| modalContent.parentNode.insertBefore(modalWrapper, modalContent); | ||
| modalWrapper.appendChild(modalContent); | ||
| modalContent.parentNode.insertBefore(overlayDiv, modalContent); | ||
| overlayDiv.appendChild(modalContent); |
There was a problem hiding this comment.
Is there any way to simplify these (lines 247-50) to make it easier to track what's being appended? Here's what I observed when testing:
- Go to
usa-modalparent, in this component library it'sdiv.margin-y-3. - Empty div is created and immediately inserted.
- Another empty div is created inside as a sibling to usa-modal.
- Finally we've appended empty divs to DOM and modifying their classes ―
⚠️ this doesn't follow the usual pattern of creating DOM and necessary attributes in JS.
It would make more sense to:
- Create elements.
- Add attributes.
- Ensure structure is what we want.
- Append fully scaffolded HTML to DOM.
There was a problem hiding this comment.
In this specific example, we need the parent overlay div on the wrapper so that setModalAttributes() can properly set up the modal's closers.
So the process looks a little more like:
- Create elements
- Add classes
- Structure overlay, wrapper, and content in correct order
- Set attributes
- Append fully scaffolded HTML to DOM
Take a look at this updated code and let me know what you think!
Updated in 270c293
mejiaj
left a comment
There was a problem hiding this comment.
Nice work. I've tested the following:
- No visual regressions.
- No functional regressions.
- No a11y regressions.
- New features: Errors when missing
id, aria-labelledby, aria-describedby. - No issues with multiple modals; tested two modals on same page.
|
@amyleadem bumping for review when you have time! |
There was a problem hiding this comment.
This is looking good! Had just a few notes about opportunities to improve the comments for quicker understanding.
I performed the following checks:
- Confirm that multiple modals are on a page works in the test repo
- Confirm no visual regressions in Storybook
- Confirm no functional regressions in Storybook
- Confirm that removing
id,aria-labelledby, oraria-describedbyattributes causes console error - Confirm that code style and comments meet standards
- Added some comments about adding detail to the function comments
- Confirm changelog
- Added some comments to the changelog PR
packages/usa-modal/src/index.js
Outdated
| modalWrapper.appendChild(modalContent); | ||
| modalContent.parentNode.insertBefore(overlayDiv, modalContent); | ||
| overlayDiv.appendChild(modalContent); | ||
| const setModalAttributes = (baseComponent, targetWrapper) => { |
There was a problem hiding this comment.
Would it make sense to rename targetWrapper to something more descriptive like modalContentWrapper?
amyleadem
left a comment
There was a problem hiding this comment.
Thanks for adding those clarifying comments, @mahoneycm. Looks good to me!
I performed the following checks:
- Confirm that multiple modals are on a page works in the test repo
- Confirm no visual regressions in Storybook
- Confirm no functional regressions in Storybook
- Confirm that removing
id,aria-labelledby, oraria-describedbyattributes causes console error - Confirm that code style and comments meet standards
- Confirm changelog
| const modalContent = baseComponent; | ||
| const modalWrapper = document.createElement("div"); | ||
| const overlayDiv = document.createElement("div"); | ||
| const createPlaceHolder = (baseComponent) => { |
There was a problem hiding this comment.
Explore cloneNode() [MDN] to allow users to add their own event listeners to modal content. Created a new issue for this #5419.
mejiaj
left a comment
There was a problem hiding this comment.
@mahoneycm can you resolve conflicts, otherwise LGTM?
Summary
Refactored Modal JavaScript for added consistency and failsafe measures. This resolves issues when initialization is called more than once on a document.
Breaking change
This is not a breaking change.
Related issue
Closes #5062
Related pull requests
Changelog PR →
Continued from #5208
Preview link
Preview link:
Modal →
Problem statement
From #5062:
After inspecting Modal JS, we saw room for improvement to align JS to be more consistent with other Dynamic Components, including adding error messages if key pieces are missing from component code.
Solution
Refactor Modal JS to:
setUpModal()function into more palatable, feature-specific functionsid,aria-labelledby, andaria-describedby.Testing and review
Review
Code Refactor:
ID, aria-labelledby, and/or aria-describedbyfromusa-modal, allow the preview to rebuild, then inspect the component preview.Multiple init in JS Frameworks
npm linknpm installnpm run startnpm link @uswds/uswdsusa-modalclass, which has been moved to hidden modal window elementTesting
ID, aria-labelledby, and aria-describedbyfromusa-modaltriggers error in console.Before opening this PR, make sure you’ve done whichever of these applies to you:
git pull origin [base branch]to pull in the most recent updates from your base and check for merge conflicts. (Often, the base branch isdevelop).npm testand confirm that all tests pass.