Skip to content

Reintroduce EuiSwitch a11y changes#2491

Merged
thompsongl merged 16 commits intoelastic:masterfrom
thompsongl:2385-switch
Oct 29, 2019
Merged

Reintroduce EuiSwitch a11y changes#2491
thompsongl merged 16 commits intoelastic:masterfrom
thompsongl:2385-switch

Conversation

@thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Oct 25, 2019

Summary

Closes #2385 and re-implements code reverted in #2255, resolving a11y issues with EuiSwitch and converting the component to TypeScript.

Added a label-less version, which uses aria-label.

Compressed and mini styles were added after the reversion, so those have been refactored.

The difficult work will come in a Kibana PR (already passing), although the addition of type on the button remedied some major problems (why is submit the default, anyways?)

Checklist

- [ ] Checked in dark mode
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox

  • Props have proper autodocs
  • Added documentation examples

- [ ] Added or updated jest tests
- [ ] Checked for breaking changes and labeled appropriately
- [ ] Checked for accessibility including keyboard-only and screenreader modes

  • A changelog entry exists and is marked appropriately

Comment on lines +52 to +56
const onClick = (e: React.MouseEvent<HTMLButtonElement>) => {
const event = (e as unknown) as EuiSwitchEvent;
event.target.checked = !checked;
onChange(event);
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that this is a breaking change even with this shim, do we still want to go this route?

I think it's fine if we want to decide that, I just didn't want this to slide in without being considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the shim still has value. Others can chime in if they disagree, though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that there is still value in providing the checked state through the event's target.

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Changes LGTM, pulled and tested locally.

@thompsongl
Copy link
Contributor Author

While doing some testing, I noticed that the label->p change makes the text non-interactive, which I don't like.

So I did some more looking and it seems that button is actually a labelable element:
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Form_labelable
https://html.spec.whatwg.org/multipage/forms.html#category-label

Thoughts on reverting that change, @myasonik?

@myasonik
Copy link
Contributor

Button is labelable but support for it is really poor. The label will be the only thing read by many screen readers and you won't get the button text. Sometimes you'll also lose the other button attributes as well (like, the aria-checked state in this case). :/

We could get around it by adding a bunch of content to the label text repeating all the info in the button but I think I'd rather add a click handler to the p.

@thompsongl thompsongl merged commit cbf9c4f into elastic:master Oct 29, 2019
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.

Reintroduce EuiSwitch a11y changes

4 participants