Skip to content

Conversation

sanason
Copy link
Contributor

@sanason sanason commented Aug 16, 2024

Summary

Fixed a bug in the usa-modal component whereby the class name was hard-coded in JavaScript. Using the PREFIX variable consistently allows users to bundle the modal package with a prefix other than usa-.

Breaking change

This is not a breaking change.

Related issue

Closes #6027

Related pull requests

Changelog PR

Preview link

Preview link:

Problem statement

Users may choose to use a different prefix in the modal component. Currently, not all of the variables use the PREFIX variable for all styles. Update the styles to allow users to bundle the modal package with a prefix other than usa-.

Solution

By replacing hardcoded variables like (".usa-modal") with available constants such as (.${MODAL_CLASSNAME}) users that choose to customize the prefix with the modal component can do so.

@sanason sanason changed the title Use classname constants consistently in modal JS file. USWDS - Modal: Use classname constants consistently in JS file. Aug 16, 2024
@sanason sanason marked this pull request as ready for review August 16, 2024 23:27
@cathybaptista cathybaptista self-requested a review September 4, 2024 16:28
@cathybaptista cathybaptista changed the title USWDS - Modal: Use classname constants consistently in JS file. USWDS - Modal: Use classname constants for all variable references in JS file for modal package.. Sep 25, 2024
@cathybaptista cathybaptista changed the title USWDS - Modal: Use classname constants for all variable references in JS file for modal package.. USWDS - Modal: Use classname constants for all variable references in JS file. Sep 25, 2024
@cathybaptista cathybaptista changed the title USWDS - Modal: Use classname constants for all variable references in JS file. USWDS - Modal: Use classname constants for all variable references in JavaScript file. Sep 25, 2024
@cathybaptista
Copy link
Contributor

To confirm this issue, I pulled this branch and modified

module.exports = {
  prefix: "different-usa",
};

Here is the test html:

class="different-usa-modal-wrapper is-visible"

when using

document.querySelector(".usa-modal-wrapper.is-visible");

The JS error is: The label's for attribute doesn't match any element id.

I then replaced

: document.querySelector(".usa-modal-wrapper.is-visible");

with :

document.querySelector(.${WRAPPER_CLASSNAME}.${VISIBLE_CLASS});

And the modal worked as expected with no error.

@mejiaj mejiaj requested a review from CTGM-Bixal October 8, 2024 13:58
@sanason
Copy link
Contributor Author

sanason commented Oct 16, 2024

Hi USWDS, anything I can do to get this merged?

@cathybaptista
Copy link
Contributor

Hi @sanson, thank you for reaching out

We have your proposed fix scheduled for the November release. We'll be reviewing and approving that fix in our current sprint.

Your custom workaround for modal isn't one we'd recommend, but it led us to confirm the double init issue that necessitated it. We'll document and investigate this because we do hope users follow our guidance to add their own modals.

Have a great day and let us know what else you need.

The USWDS Team

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.

Thanks for your contribution!

Created a test branch on site [test-modal-uswds-6027] that has this installed and uses the touchpoints modal. No regressions on interactive component pages.

@thisisdano thisisdano merged commit 3149ec7 into uswds:develop Nov 6, 2024
2 checks passed
@thisisdano
Copy link
Contributor

Thank you!

@thisisdano thisisdano mentioned this pull request Nov 12, 2024
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: Inconsistent use of classname constants in modal JS file
4 participants