scottish-government-design-system / design-system

Design System for the Scottish Government and other Scottish public sector bodies
https://designsystem.gov.scot
MIT License
27 stars 11 forks source link

[Accordion] Accordions included within `<form>` prevent submission when pressing enter key #15

Closed lewisdorigo closed 1 year ago

lewisdorigo commented 1 year ago

Description: The use of <button> without a type attribute prevents submission of forms using the enter key, when the accordion is included within the <form>.

This is because, when pressing the enter key while a form field is focused, it triggers the click event on the first submit button within a form. <button> elements without the type attribute are assumed to have the type="submit", so pressing the enter key will trigger the accordion buttons instead.

We can add type="button" to the “Open all…” button within our own markup, however, the accordion item header buttons are created in JS.

Steps to reproduce:

  1. Include the accordion component inside a <form> with multiple fields, and a submit button at the end of the form.
  2. With one of the form fields focused, press the enter key.

Expected result: The form submits.

Actual Result: The first accordion item opens.