Skip to content

USWDS - Bug: Inconsistent use of classname constants in modal JS file #6027

@sanason

Description

@sanason

Describe the bug

In the JavaScript for the modal component, CSS classname strings are referenced via const variables in most but not all places where they are used. I need the code to use the const variables in all places because I'm trying to build the modal package with my own prefix (for example, fba-usa- instead of usa-) which only works if all classnames are constructed from the PREFIX constant.

Steps to reproduce the bug

N/A exactly but here is a "bad code" example from packages/usa-modal/src/index.js.

const { prefix: PREFIX } = require("../../uswds-core/src/js/config");
const MODAL_CLASSNAME = `${PREFIX}-modal`;
...
  const openFocusEl = targetModal.querySelector(INITIAL_FOCUS)
    ? targetModal.querySelector(INITIAL_FOCUS)
    : targetModal.querySelector(".usa-modal");

Expected Behavior

And here is a good code example.

const { prefix: PREFIX } = require("../../uswds-core/src/js/config");
const MODAL_CLASSNAME = `${PREFIX}-modal`;
...
if (clickedElement.closest(`.${MODAL_CLASSNAME}`)) {...}

Related code

No response

Screenshots

No response

System setup

No response

Additional context

No response

Code of Conduct

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions