Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 8 commits into from
Aug 26, 2021

Conversation

vursen
Copy link
Contributor

@vursen vursen commented Aug 26, 2021

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
packages/button/src/vaadin-button.js Outdated Show resolved Hide resolved
packages/button/theme/lumo/vaadin-button-styles.js Outdated Show resolved Hide resolved
packages/button/theme/lumo/vaadin-button-styles.js Outdated Show resolved Hide resolved
packages/button/theme/lumo/vaadin-button-styles.js Outdated Show resolved Hide resolved
@vursen vursen force-pushed the feat/button-with-new-mixins branch from 598b6f9 to 3a274ba Compare August 26, 2021 07:10
@knoobie
Copy link
Contributor

knoobie commented Aug 26, 2021

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

@vursen
Copy link
Contributor Author

vursen commented Aug 26, 2021

@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
packages/button/src/vaadin-button.js Show resolved Hide resolved
packages/button/test/button.test.js Outdated Show resolved Hide resolved
packages/field-base/src/tabindex-mixin.js Show resolved Hide resolved
@sonarcloud
Copy link

sonarcloud bot commented Aug 26, 2021

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
Copy link
Member

@web-padawan web-padawan left a comment

Choose a reason for hiding this comment

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

LGTM 💯

@vaadin-bot
Copy link
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