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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding focus-visible styles with polyfill #3695

Merged
merged 4 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Use [the changelog guidelines](https://git.io/polaris-changelog-guidelines) to f

### Enhancements

- Added `focus-visible` polyfill and default styles ([#3695](https://github.com/Shopify/polaris-react/pull/3695))

### Bug fixes

- Fixed virtual cursor leaving dialog in `Modal`, `Navigation` and `Sheet` ([#3931](https://github.com/Shopify/polaris-react/pull/3931))
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"@types/react": "^16.9.12",
"@types/react-dom": "^16.9.4",
"@types/react-transition-group": "^4.4.0",
"focus-visible": "^5.2.0",
"lodash": "^4.17.4",
"react-transition-group": "^4.4.1"
},
Expand Down
1 change: 1 addition & 0 deletions src/components/AppProvider/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, {Component} from 'react';
import 'focus-visible/dist/focus-visible';

import type {ThemeConfig} from '../../utilities/theme';
import {ThemeProvider} from '../ThemeProvider';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ describe('<PopoverOverlay />', () => {
</PopoverOverlay>,
);

expect(document.activeElement?.className).toBe('Content');
expect(document.activeElement?.className).toContain('Content');
});

it('does not focus when autofocusTarget is set to None', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/Tooltip/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ Use only when necessary to provide an explanation for an interface element.

```jsx
<div style={{padding: '75px 0'}}>
<Tooltip content="This order has shipping labels.">
<Link>Order #1001</Link>
<Tooltip active content="This order has shipping labels.">
<TextStyle variation="strong">Order #1001</TextStyle>
</Tooltip>
</div>
```
Expand Down
1 change: 1 addition & 0 deletions src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export function Tooltip({

accessibilityNode.tabIndex = 0;
accessibilityNode.setAttribute('aria-describedby', id);
accessibilityNode.setAttribute('data-polaris-tooltip-activator', 'true');
}, [id, children]);

const handleKeyUp = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ $content-max-width: rem(200px);
padding: spacing(extra-tight) spacing(tight);
word-break: break-word;
}

[data-polaris-tooltip-activator] {
outline: 0;
@include focus-ring;

&:focus-visible {
@include focus-ring($style: 'focused');
}
}

// stylelint-disable-next-line selector-max-attribute
[data-polaris-tooltip-activator][data-focus-visible-added] {
@include focus-ring($style: 'focused');
}
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9755,6 +9755,18 @@ focus-lock@^0.6.6:
resolved "https://registry.yarnpkg.com/focus-lock/-/focus-lock-0.6.6.tgz#98119a755a38cfdbeda0280eaa77e307eee850c7"
integrity sha512-Dx69IXGCq1qsUExWuG+5wkiMqVM/zGx/reXSJSLogECwp3x6KeNQZ+NAetgxEFpnC41rD8U3+jRCW68+LNzdtw==

focus-visible@^5.2.0:
version "5.2.0"
resolved "https://registry.yarnpkg.com/focus-visible/-/focus-visible-5.2.0.tgz#3a9e41fccf587bd25dcc2ef045508284f0a4d6b3"
integrity sha512-Rwix9pBtC1Nuy5wysTmKy+UjbDJpIfg8eHjw0rjZ1mX4GNLz1Bmd16uDpI3Gk1i70Fgcs8Csg2lPm8HULFg9DQ==

follow-redirects@1.5.10:
version "1.5.10"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.5.10.tgz#7b7a9f9aea2fdff36786a94ff643ed07f4ff5e2a"
integrity sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==
dependencies:
debug "=3.1.0"

follow-redirects@^1.0.0:
version "1.13.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.0.tgz#b42e8d93a2a7eea5ed88633676d6597bc8e384db"
Expand Down