Skip to content

Use button instead of a for closing modals #446

@Atmos4

Description

@Atmos4

Describe the issue

The usage of button for closing modals makes a lot more sense than a.

  • from w3:

The button element should be used for any interaction that performs an action on the current page. The a element should be used for any interaction that navigates to another view.

  • from UX: Links only respond to Enter key presses. Buttons respond to both Enter and Space.
  • Links need to have an href attribute in order to be accessible. This forces the usage of href=#, which can confuse screen readers and will in fact perform the scroll animation unless the onclick handler returns false, which further increases verbosity.

Solutions

One solution would be to recommend button as a way to close modals, and properly style any button with class=close (or rel=prev even though it is not valid on buttons, and also a non-standard way to describe dialog closing actions).

Extending the previous solution for classless pico, we can use <form method=dialog> HTML element, which is a non-Javascript solution to closing dialogs. Alternatively if the button is already in a form, we can use <button formmethod=dialog>.

Here is a demo of the extended solution on CodePen.

If you agree on the issue, let me know which solution you like best and I can start working on a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions