Skip to content

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

Merged
merged 15 commits into from
Mar 7, 2023

Conversation

mahoneycm
Copy link
Contributor

@mahoneycm mahoneycm commented Nov 21, 2022

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:

  • Various iPhones with different Mobile Safari versions (Latest is v16.0, oldest tested was v10.3)
  • Desktop browsers(Chrome, Safari, Edge)
  • Various Android devices and browsers (Chrome, Firefox, Samsung Browser)

To Test

  • Visit Nested Forms modal page
  • Open Modal
  • Test drop down components
  • Click out of modal view or use closer buttons to close

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

Screen Shot 2022-11-21 at 12 09 41 PM

Screen Shot 2022-11-21 at 12 09 57 PM

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

Copy link
Contributor

@amyleadem amyleadem left a 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!

Copy link
Contributor

@mejiaj mejiaj left a 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 (`).

@mahoneycm mahoneycm requested review from amyleadem and mejiaj January 5, 2023 15:06
@mahoneycm
Copy link
Contributor Author

@amyleadem @mejiaj Created a unit test for nested forms using a combo box! Passing as expected currently and breaks with stopPagination()

assert.strictEqual(activeContent[0], modalWrapper);
});

it("should show the list by clicking the toggle button", () => {
Copy link
Contributor

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"?

Copy link
Contributor Author

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 😁

Copy link
Contributor Author

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");
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

@amyleadem amyleadem left a 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.

@mahoneycm mahoneycm requested a review from amyleadem January 18, 2023 22:16
Copy link
Contributor

@amyleadem amyleadem left a 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.

@mahoneycm
Copy link
Contributor Author

@thisisdano Ready for final review!

@mejiaj
Copy link
Contributor

mejiaj commented Feb 6, 2023

@mahoneycm going to move this back to review since I haven't had a chance to look over the requested changes.

Copy link
Contributor

@mejiaj mejiaj left a 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.

@mejiaj mejiaj self-requested a review February 28, 2023 19:41
Copy link
Contributor

@mejiaj mejiaj left a 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

@mejiaj mejiaj self-requested a review March 1, 2023 19:04
Copy link
Contributor

@mejiaj mejiaj left a 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.

@mejiaj mejiaj requested a review from thisisdano March 3, 2023 22:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

USWDS - Bug: Date Picker component doe not function inside modal
4 participants