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

[Focus states] Use :focus-visible over :focus for focus-ring state. #8054

Merged
merged 5 commits into from
Jan 18, 2023

Conversation

mrcthms
Copy link
Contributor

@mrcthms mrcthms commented Jan 16, 2023

WHY are these changes introduced?

Fixes #8053
Related to: #7585 and #818
We currently use a focus-ring to show a merchant which element is currently in focus. This is useful particularly for users that don't use a traditional pointer device to navigate through the admin. We currently use the :focus CSS selector to add these focus rings to interactive elements.

Whilst this is an important accessibility necessity, it can leave the admin looking very busy for merchants that do use a traditional pointer device, with focus rings appearing on every interaction.

There is a CSS selector named :focus-visible, which allows the browser to determine when to show the focus state depending on the input device that controls the focus state, and the element in question. This will allow us to persist the vital focus state visibility for users navigating the admin via keyboard, but will leave the admin feeling cleaner for those merchants using a mouse or other pointer device.

WHAT is this pull request doing?

This PR updates instances of :focus to show a focus ring and replaces them with :focus-visible. It also tidies up some legacy code in some components to detect for keyFocus only, preferring to use the browser standard :focus-visible rather than some internal component logic to figure out when focus is being managed by a keyboard.

Note: The Listbox remains untouched as the focus state logic there is pretty custom and will require somebody with more domain knowledge to update that component

How to 🎩

🖥 Local development instructions
🗒 General tophatting guidelines
📄 Changelog guidelines

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

export function Playground() {
  return (
    <Page title="Playground">
      {/* Add the code you want to test in here */}
    </Page>
  );
}

🎩 checklist

@mrcthms
Copy link
Contributor Author

mrcthms commented Jan 16, 2023

/snapit

@github-actions
Copy link
Contributor

github-actions bot commented Jan 16, 2023

size-limit report 📦

Path Size
polaris-react-cjs 212.09 KB (-0.1% 🔽)
polaris-react-esm 137.08 KB (-0.17% 🔽)
polaris-react-esnext 192.65 KB (-0.13% 🔽)
polaris-react-css 42.02 KB (+0.06% 🔺)

@mrcthms
Copy link
Contributor Author

mrcthms commented Jan 16, 2023

/snapit

@github-actions
Copy link
Contributor

🫰✨ Thanks @mrcthms! Your snapshots have been published to npm.

Test the snapshots by updating your package.json with the newly published versions:

yarn add @shopify/[email protected]
yarn add @shopify/[email protected]
yarn add @shopify/[email protected]

@mrcthms mrcthms force-pushed the mrcthms-focus-visible branch 2 times, most recently from 432e90d to 53e1458 Compare January 17, 2023 11:41
@Shopify Shopify deleted a comment from github-actions bot Jan 17, 2023
@chloerice chloerice self-requested a review January 17, 2023 16:10
Copy link
Member

@chloerice chloerice left a comment

Choose a reason for hiding this comment

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

Tophatted all affected components and all are as expected between keyboard and mouse focus, thanks for tackling this @mrcthms!! 🙌🏽 I'll update the Listbox, it should only show the surface-selected state and not use focus-ring (purely a CSS change)

@@ -1347,7 +1347,7 @@ $nav-min-window: em(layout-width(page-with-nav));
@include high-contrast-outline;
}

&:focus {
&:focus-visible {
Copy link
Member

Choose a reason for hiding this comment

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

This code doesn't need to be changed as it isn't published, it's just a reference to the legacy Sass styles.

@mrcthms
Copy link
Contributor Author

mrcthms commented Jan 17, 2023

Thanks @chloerice, much appreciated! LMK if you want a reviewer of the Listbox update.

@mrcthms mrcthms merged commit c44c96c into main Jan 18, 2023
@mrcthms mrcthms deleted the mrcthms-focus-visible branch January 18, 2023 10:22
mrcthms pushed a commit that referenced this pull request Jan 19, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/[email protected]

### Minor Changes

- [#8049](#8049)
[`dca31f2a0`](dca31f2)
Thanks [@leileu](https://github.com/leileu)! - Added 8 minor icons for
metafields


- [#8069](#8069)
[`f67e2997e`](f67e299)
Thanks [@leileu](https://github.com/leileu)! - Added file minor icon


- [#8063](#8063)
[`d5da4778c`](d5da477)
Thanks [@eric-blue](https://github.com/eric-blue)! - Added minor icon
for diamond_alert


- [#8037](#8037)
[`1aeed2414`](1aeed24)
Thanks [@dGoligorsky](https://github.com/dGoligorsky)! - Added major and
minor icon for Magic

### Patch Changes

- [#8085](#8085)
[`56b757036`](56b7570)
Thanks [@sarahill](https://github.com/sarahill)! - Added icon name for
magic major and minor


- [#8066](#8066)
[`68acc4593`](68acc45)
Thanks [@kyledurand](https://github.com/kyledurand)! - Added better
error documentation on icon validation

## @shopify/[email protected]

### Minor Changes

- [#8054](#8054)
[`c44c96c6b`](c44c96c)
Thanks [@mrcthms](https://github.com/mrcthms)! - Update focus states to
be present on :focus-visible rather than :focus

### Patch Changes

- [#8080](#8080)
[`1c926b9da`](1c926b9)
Thanks [@LauraAubin](https://github.com/LauraAubin)! - Added an optional
`zIndexOverride` prop to `Tooltip`


- [#8077](#8077)
[`dc2ed0a5c`](dc2ed0a)
Thanks [@kyledurand](https://github.com/kyledurand)! - Removed data
attribute css from legacy polyfill


- [#8040](#8040)
[`ba6b04c79`](ba6b04c)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed modal
footer vertical alignment when noScroll is true

- Updated dependencies
\[[`dca31f2a0`](dca31f2),
[`56b757036`](56b7570),
[`f67e2997e`](f67e299),
[`68acc4593`](68acc45),
[`d5da4778c`](d5da477),
[`1aeed2414`](1aeed24)]:
    -   @shopify/[email protected]

## @shopify/[email protected]



## [email protected]

### Minor Changes

- [#8027](#8027)
[`8fc0fefdf`](8fc0fef)
Thanks [@qt314](https://github.com/qt314)! - Add tooling section to
document tools help build and maintain Polaris in consuming
applications.

### Patch Changes

- Updated dependencies
\[[`dca31f2a0`](dca31f2),
[`56b757036`](56b7570),
[`f67e2997e`](f67e299),
[`1c926b9da`](1c926b9),
[`c44c96c6b`](c44c96c),
[`dc2ed0a5c`](dc2ed0a),
[`ba6b04c79`](ba6b04c),
[`68acc4593`](68acc45),
[`d5da4778c`](d5da477),
[`1aeed2414`](1aeed24)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@gwyneplaine gwyneplaine mentioned this pull request Feb 14, 2023
juzser pushed a commit to juzser/polaris that referenced this pull request Jul 27, 2023
…hopify#8054)

### WHY are these changes introduced?

Fixes Shopify#8053
Related to: Shopify#7585 and
Shopify#818
We currently use a focus-ring to show a merchant which element is
currently in focus. This is useful particularly for users that don't use
a traditional pointer device to navigate through the admin. We currently
use the :focus CSS selector to add these focus rings to interactive
elements.

Whilst this is an important accessibility necessity, it can leave the
admin looking very busy for merchants that do use a traditional pointer
device, with focus rings appearing on every interaction.

There is a CSS selector named :focus-visible, which allows the browser
to determine when to show the focus state depending on the input device
that controls the focus state, and the element in question. This will
allow us to persist the vital focus state visibility for users
navigating the admin via keyboard, but will leave the admin feeling
cleaner for those merchants using a mouse or other pointer device.

### WHAT is this pull request doing?

This PR updates instances of `:focus` to show a focus ring and replaces
them with `:focus-visible`. It also tidies up some legacy code in some
components to detect for keyFocus only, preferring to use the browser
standard `:focus-visible` rather than some internal component logic to
figure out when focus is being managed by a keyboard.

_Note: The Listbox remains untouched as the focus state logic there is
pretty custom and will require somebody with more domain knowledge to
update that component_

<!-- ℹ️ Delete the following for small / trivial changes -->

### How to 🎩

🖥 [Local development
instructions](https://github.com/Shopify/polaris/blob/main/README.md#local-development)
🗒 [General tophatting
guidelines](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md)
📄 [Changelog
guidelines](https://github.com/Shopify/polaris/blob/main/.github/CONTRIBUTING.md#changelog)

<!--
  Give as much information as needed to experiment with the component
  in the playground.
-->

<details>
<summary>Copy-paste this code in
<code>playground/Playground.tsx</code>:</summary>

```jsx
import React from 'react';
import {Page} from '../src';

export function Playground() {
  return (
    <Page title="Playground">
      {/* Add the code you want to test in here */}
    </Page>
  );
}
```

</details>

### 🎩 checklist

- [x] Tested on
[mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing)
- [x] Tested on [multiple
browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers)
- [x] Tested for
[accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md)
- [x] Updated the component's `README.md` with documentation changes
- [x] [Tophatted
documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md)
changes in the style guide
juzser pushed a commit to juzser/polaris that referenced this pull request Jul 27, 2023
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @shopify/[email protected]

### Minor Changes

- [Shopify#8049](Shopify#8049)
[`dca31f2a0`](Shopify@dca31f2)
Thanks [@leileu](https://github.com/leileu)! - Added 8 minor icons for
metafields


- [Shopify#8069](Shopify#8069)
[`f67e2997e`](Shopify@f67e299)
Thanks [@leileu](https://github.com/leileu)! - Added file minor icon


- [Shopify#8063](Shopify#8063)
[`d5da4778c`](Shopify@d5da477)
Thanks [@eric-blue](https://github.com/eric-blue)! - Added minor icon
for diamond_alert


- [Shopify#8037](Shopify#8037)
[`1aeed2414`](Shopify@1aeed24)
Thanks [@dGoligorsky](https://github.com/dGoligorsky)! - Added major and
minor icon for Magic

### Patch Changes

- [Shopify#8085](Shopify#8085)
[`56b757036`](Shopify@56b7570)
Thanks [@sarahill](https://github.com/sarahill)! - Added icon name for
magic major and minor


- [Shopify#8066](Shopify#8066)
[`68acc4593`](Shopify@68acc45)
Thanks [@kyledurand](https://github.com/kyledurand)! - Added better
error documentation on icon validation

## @shopify/[email protected]

### Minor Changes

- [Shopify#8054](Shopify#8054)
[`c44c96c6b`](Shopify@c44c96c)
Thanks [@mrcthms](https://github.com/mrcthms)! - Update focus states to
be present on :focus-visible rather than :focus

### Patch Changes

- [Shopify#8080](Shopify#8080)
[`1c926b9da`](Shopify@1c926b9)
Thanks [@LauraAubin](https://github.com/LauraAubin)! - Added an optional
`zIndexOverride` prop to `Tooltip`


- [Shopify#8077](Shopify#8077)
[`dc2ed0a5c`](Shopify@dc2ed0a)
Thanks [@kyledurand](https://github.com/kyledurand)! - Removed data
attribute css from legacy polyfill


- [Shopify#8040](Shopify#8040)
[`ba6b04c79`](Shopify@ba6b04c)
Thanks [@kyledurand](https://github.com/kyledurand)! - Fixed modal
footer vertical alignment when noScroll is true

- Updated dependencies
\[[`dca31f2a0`](Shopify@dca31f2),
[`56b757036`](Shopify@56b7570),
[`f67e2997e`](Shopify@f67e299),
[`68acc4593`](Shopify@68acc45),
[`d5da4778c`](Shopify@d5da477),
[`1aeed2414`](Shopify@1aeed24)]:
    -   @shopify/[email protected]

## @shopify/[email protected]



## [email protected]

### Minor Changes

- [Shopify#8027](Shopify#8027)
[`8fc0fefdf`](Shopify@8fc0fef)
Thanks [@qt314](https://github.com/qt314)! - Add tooling section to
document tools help build and maintain Polaris in consuming
applications.

### Patch Changes

- Updated dependencies
\[[`dca31f2a0`](Shopify@dca31f2),
[`56b757036`](Shopify@56b7570),
[`f67e2997e`](Shopify@f67e299),
[`1c926b9da`](Shopify@1c926b9),
[`c44c96c6b`](Shopify@c44c96c),
[`dc2ed0a5c`](Shopify@dc2ed0a),
[`ba6b04c79`](Shopify@ba6b04c),
[`68acc4593`](Shopify@68acc45),
[`d5da4778c`](Shopify@d5da477),
[`1aeed2414`](Shopify@1aeed24)]:
    -   @shopify/[email protected]
    -   @shopify/[email protected]

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
@chloerice chloerice added 2023 Contribution tracking for 2023 Contribution Tracking contribution in conjuction with year and type, e.g., "Component" + "Contribution" + "2023" labels Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2023 Contribution tracking for 2023 Component Contribution Tracking contribution in conjuction with year and type, e.g., "Component" + "Contribution" + "2023" Engineering
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Polaris components to only show focus state when navigating with keyboard
2 participants