web-components icon indicating copy to clipboard operation
web-components copied to clipboard

[icon] Add support for setting aria-label on the icon [1 day]

Open web-padawan opened this issue 4 years ago • 2 comments

Motivation

We make the icons hidden from screen readers in #2936 but in some cases users might want to override this.

Proposed solution

Inspired by how the <lion-icon> web component handles this:

static get properties() {
  return {
    // ...
    ariaLabel: {
      type: String,
      value: '',
      observer: '_ariaLabelChanged'
      reflectToAttribute: true
    }
  };
}

_ariaLabelChanged(ariaLabel) {
  if (ariaLabel) {
    this.setAttribute('aria-hidden', 'false');
  } else {
    this.setAttribute('aria-hidden', 'true');
  }
}

web-padawan avatar Oct 26 '21 15:10 web-padawan

We could find the way of properly announcing icons. Take a look at the existing solutions.

yuriy-fix avatar Aug 02 '22 12:08 yuriy-fix

Based on https://www.sarasoueidan.com/blog/accessible-icon-buttons/

Since the button doesn’t have any text content in it, nor does it have a label defined using any ARIA attributes, the icon itself will now be used as a name. Since the icon has a clear label, that label will be used as the accessible name for the button.

Please note that I do not recommend using this technique as it fails in some browser / screen reader combinations. Personally, I’d not use the SVG icon itself to provide a label for the button when I can provide one on the button itself directly

web-padawan avatar Aug 02 '22 12:08 web-padawan