Skip to content

Consider improving accessibility support with aria-role #22

Closed

Description

@AoDev

Adding an aria role would improve accessibility of this component.

I think the best fit for this component would be to add the switch role per the Mozilla guidelines here.

The gist of it would be to add:

  • role="switch"
  • aria-checked={checked}

on the outer span.

In render method:

...
const checked = this.state.checked;
...
<span
  {...restProps}
  role="switch"
  aria-checked={checked}
  className={switchClassName}
  tabIndex={switchTabIndex}
  ref={this.saveNode}
  onKeyDown={this.handleKeyDown}
  onClick={this.toggle}
  onMouseUp={this.handleMouseUp}
>
  <span className={`${prefixCls}-inner`}>
    {checked ? checkedChildren : unCheckedChildren}
  </span>
</span>

Activity

  1. saitonakamura commented on Sep 6, 2018

    @saitonakamura
    Contributor

    Also it's a good idea to use button instead of span cause button includes a lot of a11y stuff out of the box, like tab index, reacting to space and enter etc. so you can save some codelines

  2. saitonakamura commented on Sep 6, 2018

    @saitonakamura
    Contributor

    Heydon Pickering has a really good blog about a11y btw https://inclusive-components.design/toggle-button/#theswitchrole

  3. zombieJ commented on Sep 6, 2018

    @zombieJ
    Member

    Welcome PR for this : )

  4. saitonakamura commented on Sep 10, 2018

    @saitonakamura
    Contributor

    Here you go #26

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

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