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

[Link] Improve accessibility of focus styles #1425

Merged
merged 1 commit into from
May 10, 2019
Merged

Conversation

ry5n
Copy link
Contributor

@ry5n ry5n commented May 8, 2019

WHY are these changes introduced?

Fixes https://github.com/Shopify/polaris-ux/issues/40 and https://github.com/Shopify/polaris-ux/issues/156

Original design

In the original issues, we landed on some more accessible focus styles for links:

56589956-33421c00-65b4-11e9-8215-6dcac9315bcc copy

Implementation challenges

In implementing these, however, I ran into some problems. The main one is that if Link remains styled as an inline element, image links look bad out of the box:

Image link issue

We could fix this by making all images in Polaris block-level by default. This is usually what you want, but may have knock-on effects in consuming apps. Another way would be to set links to be inline-flex, but has similar risks for existing apps.

Current approach: go with browser defaults

To avoid breaking changes, I’ve opted to go a different route from the original designs and strip back to browser default styles instead.

Here’s how things look now in different browsers. I left out iOS Safari since I haven’t been able to get the external keyboard emulation working in order to visualize element focus.

Chrome (Android)

Chrome Android

Chrome (Mac)

Chrome Mac

Safari (Mac)

Safari Mac

Edge (Windows)

Edge Windows

Firefox (Mac)

Firefox Mac


How to review

My big question is: are we OK moving forward with this approach? It’s not ideal, but it’s also a big improvement on the inaccessible styles we have today.

Please give feedback based on either the screenshots attached, or 🎩using the playground below:

Copy-paste this code in playground/Playground.tsx:
import * as React from 'react';
import {Page, Link} from '../src';

interface State {}

export default class Playground extends React.Component<never, State> {
  render() {
    return (
      <Page title="Playground">
        <p style={{marginBottom: 16}}>
          Focus styles have to account for text wrapping.{' '}
          <Link url="#">Text links</Link> are intended for use within other
          text.
        </p>

        <p style={{marginBottom: 16}}>
          Focus styles have to account for text wrapping.{' '}
          <Link monochrome url="#">
            Monochrome links
          </Link>{' '}
          are also intended for use within other text.
        </p>

        <p style={{marginBottom: 16, maxWidth: 400}}>
          Focus styles have to account for text wrapping. Focus styles have to
          account for text wrapping.{' '}
          <Link url="#">Very long link that will wrap at some point</Link> are
          intended for use within other text.
        </p>

        <Link url="#">
          <img src="http://placekitten.com/80/80" alt="Kitten" />
        </Link>
      </Page>
    );
  }
}

Next steps

If we’re OK with this experience, I’ll update documentation and changelog and ship. We can then consider what larger changes we’d want to make to Polaris’ foundations to support a better implementation/breaking change later.

🎩 checklist

@kaelig
Copy link
Contributor

kaelig commented May 8, 2019

I see the proposed solution to be sub-optimal (as mentioned above), but considering the state of CSS in 2019, it's probably the most appropriate way to achieve the intended results today.

The future is promising, though!

Suggestions for the long term

Some pretty cool CSS pseudo-classes are coming as part of the CSS Selectors level 4 spec. For reference, I thought I'd mention them in this issue.

2020? :focus-visible

Partial support today, expect good support for most of our users by 2020?

Targets element to show a focus ring (custom or native) only when appropriate (as in: shows a ring to a keyboard user, but not to a mouse-only user), using the :focus-visible pseudo-class.

a:focus-visible {
  // custom focus outline, only appears when appropriate
}

>2020? a:has(> img)

No support today… perhaps in a year or 2?

To improve the look and feel of custom focus rings on images, we could use the :has pseudo-class and target specifically images that happen to be in links (rather than showing the focus ring on the inline link itself.

a:has(> img):focus-visible {
  // remove outline on the link itself

  img {
    // apply custom focus outline on the img
  }
}

⚠️ the above code is purely speculative, the spec may change 🤷‍♂

@sarahill
Copy link
Contributor

sarahill commented May 8, 2019

@kaelig @ry5n I'm curious as to why this approach, using the browser defaults, is suboptimal? It is visually inconsistent across browsers but I'm generally all for using the defaults. Is there more to this than visual consistency?

This seems like a big improvement to me 👍

@dpersing
Copy link
Contributor

dpersing commented May 8, 2019

@kaelig We're tracking :focus-visible viability in #818, just for reference.

@ry5n I wouldn't worry so much about testing on iOS specifically, but making sure focus looks okay when the page is viewed at a mobile breakpoint. We can do that by resizing the window or resizing text-only in Firefox.

Copy link
Contributor

@dpersing dpersing left a comment

Choose a reason for hiding this comment

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

This looks good to me. I tested in Firefox and Edge as well, including in High Contrast for Edge, and with text resizing. Everything works as I'd expect from the defaults!

We should probably prepare a statement about why we've decided to do this, since I expect that we'll get some complaints about it being "ugly".

@ry5n
Copy link
Contributor Author

ry5n commented May 10, 2019

Good idea @dpersing! I drafted an explanation which we can jam on here: https://docs.google.com/document/d/17uH9fLWPN7ENugsQ1C91I_9izodqd_wR2U5Lcb_9B20/edit?usp=sharing

@ry5n ry5n changed the title [Link][WIP] Improve accessibility of focus styles [Link] Improve accessibility of focus styles May 10, 2019
@ry5n ry5n force-pushed the accessible-link-focus branch from 047267b to a2c09ff Compare May 10, 2019 22:03
@BPScott BPScott requested a deployment to polaris-react-pr-1425 May 10, 2019 22:03 Abandoned
@ry5n
Copy link
Contributor Author

ry5n commented May 10, 2019

I checked the style guide and I don’t think this needs any component documentation updates. Going to ship when everything goes green 🍏

@ry5n ry5n merged commit e569478 into master May 10, 2019
@ry5n ry5n deleted the accessible-link-focus branch May 10, 2019 22:15
@dpersing
Copy link
Contributor

dpersing commented May 10, 2019

This PR also fixes https://github.com/Shopify/polaris-ux/issues/242!

@ry5n
Copy link
Contributor Author

ry5n commented May 10, 2019

@sarahill I realized I never answered your question about why browser defaults are sub-optimal.

There’s a couple of reasons in my opinion:

  1. On the face of it, some browsers have more accessible styles than others. Safari’s styles, seem pretty darn light to me, and the 1px dotted border used by several others is hard to see around images. If we can do better, why not?

  2. Not all browsers adjust their focus style based on the background. On dark backgrounds, even otherwise good browser defaults can be hard to see.

  3. It would be nice to have focus styles that matched the look and feel of the interface (assuming they’re visible and familiar).

@dpersing
Copy link
Contributor

Im optimistic we can bake a few universal, accessible, custom focus styles into the next style guide iteration!

@sarahill
Copy link
Contributor

@ry5n Thanks for the reply! I dug into it a bit more after I asked the question too. I found pretty much the same things you stated above. This'll be a good one to see evolve. Nice work, Ryan 🎉

@danrosenthal danrosenthal temporarily deployed to production May 13, 2019 18:17 Inactive
@mirualves mirualves requested review from mirualves and removed request for mirualves May 13, 2019 18:21
@mirualves
Copy link
Contributor

Looking good!

Copy link
Contributor

@mirualves mirualves left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants