Skip to content

USWDS - Combobox: Input loses usa-input--error on initialization #5936

@mahoneycm

Description

@mahoneycm

Summary

Combobox markup is built with a select element that is moved offscreen and replaced with an input element during initialization. Classes set on the select element are not transferred to the new input element, making it difficult for users to use classes to style the input.

Steps to reproduce the bug

  1. Add combobox markup to a page.
  2. Add additional styles to the select element.
  3. Open page in browser.
  4. Inspect combobox input.
  5. Confirm classes are missing.

Expected behavior

Classes should be transferred to the input element.

This behavior is similar to how usa-modal transfers attributes to its placeholder or file input moves dropzone classes from the file input to the file input parent.

Modal

modalAttributes.forEach((attribute) => {
originalLocationPlaceHolder.setAttribute(
`data-original-${attribute.name}`,
attribute.value
);
});

File input

// Adds class names and other attributes
fileInputEl.classList.remove(DROPZONE_CLASS);
fileInputEl.classList.add(INPUT_CLASS);
fileInputParent.classList.add(DROPZONE_CLASS);

Additional context

This functionality is need to initialize combobox in it's error state, as discovered in #5879

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions