Skip to content

Buttons which do not submit a form should be assigned type #3563

Description

@aduth

Description

Most (all?) component examples which incorporate button element markup do not currently assign a type attribute.

Example (Accordion):

<button class="usa-accordion__button"
aria-expanded="{{ item.expanded | default('false') }}"
aria-controls="{{ accordion.id_prefix }}{{ item.id }}">

In absence of an assigned type, the default value is submit, which inherits the semantics of form submission.

Reference: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#attr-type

Arguably, many of these buttons are not intended to be interpreted as submit buttons. Instead, the use-case of type="button" applies instead.

From the above reference:

button: The button has no default behavior, and does nothing when pressed by default. It can have client-side scripts listen to the element's events, which are triggered when the events occur.

The default behavior of submit buttons would cause their placement within a form element to trigger the form submission upon click. In the case of USWDS, there is no known user-facing issues by omitting type due to the fact that the default behavior of buttons is prevented.

Example (Accordion):

[CLICK]: {
[BUTTON](event) {
event.preventDefault();

However:

  • Semantically, any technology which crawls the markup may infer these as submit buttons. It's not clear to me if there are specific examples of this.
  • event.preventDefault() would not be needed if these were assigned type="type", which could serve as a simplification

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions