-
Notifications
You must be signed in to change notification settings - Fork 1k
USWDS: Modal with nested forms. Resolves #4953 #5049
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
Conversation

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 work! The writeup is excellent and the fix feels clean. Thanks for building out a new story for demo and testing. This is all super helpful!
Everything seems to be working as expected in my browser testing. What do you think about adding a unit test for this functionality?
Also, I do think that there is an opportunity to improve the esc
functionality here. I think it would be best if pressing esc
while the form elements are open should close only the form element, not the modal. This could be out of scope for this issue though and might require further discussion.
Tested in:
- Chrome
- Firefox
- Safari
- iOS Safari
- Edge for mac
- VoiceOver
- VoiceOver Gestures
Let me know if you have questions!

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.
Looks good! I appreciate the very detailed PR notes.
Works on Safari iPhone 6 with iOS 13.4 (browserstack). I also tried testing this on an iPhone 5, but it didn't support JS template literals (`).
@amyleadem @mejiaj Created a unit test for nested forms using a combo box! Passing as expected currently and breaks with |
assert.strictEqual(activeContent[0], modalWrapper); | ||
}); | ||
|
||
it("should show the list by clicking the toggle button", () => { |
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.
Wondering if this could be more clear. Maybe something like "Displays combobox list when clicked"?
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.
Oh yeah I copied this from the combo box test, I'll update this to be more clear 😁
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.
Do you think I should add a note about "Ensuring event propagation" at the end to explain why we did that test?
@@ -0,0 +1,161 @@ | |||
const assert = require("assert"); |
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 am curious why a new spec.js
file and template
were created for nested forms. The files seem very similar. Would it be possible to just add these updates and the ones from modal-nested-form.template.html
to modal.spec.js
and test/template.html
instead of creating new files?
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 believe I had a discussion with @mejiaj about the test and we mentioned creating a new test with the nested form. I also referenced combo box which has a different template and test for each of its variants.
Happy to make this the sole test if we prefer to do it all in one sweep!
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.
@mejiaj do you have a preference on this?
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.
@amyleadem @mahoneycm initially I suggested this as it's own test to keep the template and code simple. It looks like the test template and code are pretty much identical. In that case it makes sense to combine into one.
I'm okay if we simplify the test code to bare minimum or combine them into a single modal.spec.js
.
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 for adding the unit test! The component and test both appear to work as expected. I had a couple of comments about the file structure and the test description, but other than that I think it is looking good.
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 work! I approve, but am happy to defer to @mejiaj's preference about test file structure as described in this thread.
@thisisdano Ready for final review! |
@mahoneycm going to move this back to review since I haven't had a chance to look over the requested changes. |
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.
Functionality and test is good! Added some comments so this work is more in line with other component tests.
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.
@mahoneycm no issues with functionality, everything looks good. But ran into an issue on npm run build:html
, which is what we use for the HTML code examples on USWDS-Site. Could you please take a look?
The compile error:
> @uswds/[email protected] build:html
> webpack build --config ./webpack.twig.config.js && npm run prettier:html
assets by status 709 KiB [cached] 193 assets
./html-templates/main.js 1 bytes [built] [code generated]
ERROR in Conflict: Multiple assets emit different content to the same filename usa-modal.html
ERROR in Conflict: Multiple assets emit different content to the same filename usa-modal~forced-action.html
ERROR in Conflict: Multiple assets emit different content to the same filename usa-modal~large.html
webpack 5.58.1 compiled with 3 errors in 1898 ms
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've made a small change to the test pattern structure in fec99fa. This doesn't affect the functionality ― just uses the standard test template pattern.
npm run build:html
still works as expected.
Preview →
Description
Resolves #4953
In its current iteration, the modal component watches all clicks while the modal is open and looks to see if it contains the
CLOSER_ATTRIBUTE
to trigger the modal to close. If it does not contain this attribute, it stops propagation which causes any other click events to fail.As pointed out in #4953, this would cause some form elements to not function properly if they are nested in a modal. Consider login/registration pop-ups or scheduling assistants.
Based on the blame for that line of code, it appears the original modal creator tried to remove the stop propagation before but needed to maintain it because of a mobile safari bug. I'm not positive of what the bug was at this time but I believe this issue on stack overflow may be related. Here the user has a modal that closes when the input is tapped.
In this PR I've removed the
stopPropagation
function and created a modal with two form elements within it. After testing on various browsers and versions of mobile safari, it appears to work as expected.Browsers Tested:
To Test
Currently pressing the escape key closes the entire modal, not just the focused element. We can discuss if we'd like to change this moving forward
Screenshots
npm test
and make sure the tests for the files you have changed have passed.