Skip to content

feat!: use role attribute instead of native button - #2394

Merged
web-padawan merged 8 commits into
masterfrom
feat/button-with-new-mixins
Aug 26, 2021
Merged

web-padawan merged 8 commits into
masterfrom
feat/button-with-new-mixins

Conversation

@vursen

@vursen vursen commented Aug 26, 2021 •

Copy link
Copy Markdown
Contributor

Introduction

There are 2 approaches suggested by Tetralogical (#132) on how to organize the HTML structure of the button so that it would become more accessible for screen readers.

1st approach (prototyped and currently used in @vaadin/button):

The approach is based on the native <button> element.

<vaadin-button part="vaadin-login-submit" theme="primary contained">
  # shadow-root
  <button class="vaadin-button-container">
    <span part="prefix">
      <slot name="prefix"></slot>
    </span>
    <span part="label">
      <slot></slot>
    </span>
    <span part="suffix">
      <slot name="suffix"></slot>
    </span>
  </button>
  # end shadow-root

  Log in
</vaadin-button>

2nd approach:

The approach is based on the [tabindex=0] and [role=button] attributes which should be set on the button host.

<vaadin-button part="vaadin-login-submit" theme="primary contained" tabindex="0" role="button">
  # shadow-root
  <div class="vaadin-button-container">
    <div part="prefix">
      <slot name="prefix"></slot>
    </div>
    <div part="label">
      <slot></slot>
    </div>
    <div part="suffix">
      <slot name="suffix"></slot>
    </div>
  </div>
  # end shadow-root

  Log in
</vaadin-button>

While the current implementation of the button is based on the 1st approach (with the native button), this approach supposes us to make some changes in the Lumo and Material themes (moving padding from the host on the native button in particular) in order to adjust them for the new HTML structure.

The 2nd approach, on the other hand, doesn't suppose any changes in the themes and also allows us to get rid of ControlStateMixin in favor of the modern TabIndexMixin, FocusMixin.

The 2nd approach also provides a more convenient HTML structure that makes easier the future removal of the <span> wrappers, see #955 (comment).


This PR aims at giving an implementation for the 2nd approach as it has been considered to be more advantageous.

Part of #2224

Related a11y issues

Type of change

  • Feature

Checklist

  • I have read the contribution guide: https://vaadin.com/docs-beta/latest/guide/contributing/overview/
  • I have added a description following the guideline.
  • The issue is created in the corresponding repository and I have referenced it.
  • I have added tests to ensure my change is effective and works as intended.
  • New and existing tests are passing locally with my change.
  • I have performed self-review and corrected misspellings.

Additional for Feature type of change

  • Enhancement / new feature was discussed in a corresponding GitHub issue and Acceptance Criteria were created.

@vursen vursen changed the title feat: use FocusMixin and TabindexMixin for the new button feat: use FocusMixin and TabindexMixin for new button Aug 26, 2021
@vursen vursen changed the title feat: use FocusMixin and TabindexMixin for new button feat: improve button accessibility removing native button in favor of role attribute Aug 26, 2021
@vursen vursen changed the title feat: improve button accessibility removing native button in favor of role attribute feat: remove native button in favor of role attribute Aug 26, 2021
@vursen vursen added the a11y Accessibility issue label Aug 26, 2021
@vursen vursen changed the title feat: remove native button in favor of role attribute feat: use role attribute instead of native button Aug 26, 2021
Comment thread packages/button/src/vaadin-button.js Resolved
@vursen
vursen force-pushed the feat/button-with-new-mixins branch from 598b6f9 to 3a274ba Compare August 26, 2021 07:10
@knoobie

knoobie commented Aug 26, 2021

Copy link
Copy Markdown
Contributor

Just a note: if you change the underlying implementation from a native button to role="button" - keep in mind that the SPACE and ENTER key work as well to trigger the action. See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role#keyboard_interactions

Comment thread packages/button/test/button.test.js Resolved
@vursen

vursen commented Aug 26, 2021

Copy link
Copy Markdown
Contributor Author

@knoobie Thank you for the feedback!

Just a note: if you change the underlying implementation from a native button to role="button" - keep in mind that the SPACE and ENTER key work as well to trigger the action. See https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/button_role#keyboard_interactions

Currently, the button inherits ActiveMixin that aims to support activating the element with both Space and Enter.

@vursen
vursen force-pushed the feat/button-with-new-mixins branch from 1a08a33 to acec79c Compare August 26, 2021 10:57
@vursen
vursen marked this pull request as ready for review August 26, 2021 12:00
@vursen
vursen requested a review from web-padawan August 26, 2021 13:37
Comment thread packages/button/src/vaadin-button.js Resolved
Comment thread packages/button/test/button.test.js Resolved
@sonarqubecloud

Copy link
Copy Markdown

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 4 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@web-padawan web-padawan changed the title feat: use role attribute instead of native button feat!: use role attribute instead of native button Aug 26, 2021

@web-padawan web-padawan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯

@web-padawan
web-padawan merged commit 036e0a2 into master Aug 26, 2021
@web-padawan
web-padawan deleted the feat/button-with-new-mixins branch August 26, 2021 14:27
@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with platform 22.0.0.alpha2 and is also targeting the upcoming stable 22.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants