Skip to content

Commit 5f85394

Browse files
authored
Remove useMouseIntent in favor of focus-visible (#1157)
1 parent 0b56781 commit 5f85394

File tree

8 files changed

+28
-58
lines changed

8 files changed

+28
-58
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/components": major
3+
---
4+
5+
Removed `useMouseIntent` in favor of [`:focus-visible`](https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible). With the removal of `useMouseIntent`, the `intent-mouse` class will no longer be added to the `<body>`. Since `:focus-visible` is a relatively new psuedo-class, a polyfill is included. Any focused elements that meet the criteria for `:focus-visible` will also have a `focus-visible` class added to them by the polyfill.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@types/styled-system__theme-get": "5.0.1",
5757
"classnames": "^2.2.5",
5858
"deepmerge": "4.2.2",
59+
"focus-visible": "5.2.0",
5960
"polished": "3.5.2",
6061
"react-is": "16.10.2",
6162
"styled-system": "5.1.2"

src/BaseStyles.tsx

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
import React from 'react'
22
import styled, {createGlobalStyle} from 'styled-components'
33
import {COMMON, SystemCommonProps, SystemTypographyProps, TYPOGRAPHY} from './constants'
4-
import useMouseIntent from './hooks/useMouseIntent'
54
import {ComponentProps} from './utils/types'
65

76
const GlobalStyle = createGlobalStyle`
87
* { box-sizing: border-box; }
98
body { margin: 0; }
109
table { border-collapse: collapse; }
11-
body.intent-mouse {
12-
[role="button"]:focus,
13-
[role="tabpanel"][tabindex="0"]:focus,
14-
button:focus,
15-
summary:focus,
16-
a:focus {
17-
outline: none;
18-
box-shadow: none;
19-
}
20-
21-
[tabindex="0"]:focus,
22-
details-dialog:focus {
23-
outline: none;
24-
}
10+
11+
[role="button"]:focus:not(:focus-visible):not(.focus-visible),
12+
[role="tabpanel"][tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
13+
button:focus:not(:focus-visible):not(.focus-visible),
14+
summary:focus:not(:focus-visible):not(.focus-visible),
15+
a:focus:not(:focus-visible):not(.focus-visible) {
16+
outline: none;
17+
box-shadow: none;
18+
}
19+
20+
[tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
21+
details-dialog:focus:not(:focus-visible):not(.focus-visible) {
22+
outline: none;
2523
}
2624
`
2725

@@ -34,7 +32,10 @@ export type BaseStylesProps = ComponentProps<typeof Base>
3432

3533
function BaseStyles(props: BaseStylesProps) {
3634
const {children, ...rest} = props
37-
useMouseIntent()
35+
36+
// load polyfill for :focus-visible
37+
require('focus-visible')
38+
3839
return (
3940
<Base {...rest} data-portal-root>
4041
<GlobalStyle />

src/SelectMenu/SelectMenuItem.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export const listItemStyles = css`
6565
6666
// can hover states
6767
@media (hover: hover) {
68-
body:not(.intent-mouse) .SelectMenu-item:focus,
6968
&:hover,
7069
&:active,
7170
&:focus {

src/__tests__/__snapshots__/SelectMenu.tsx.snap

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ exports[`SelectMenu right-aligned modal has right: 0px 1`] = `
246246
}
247247
248248
@media (hover:hover) {
249-
.c5 body:not(.intent-mouse) .SelectMenu-item:focus,
250249
.c5:hover,
251250
.c5:active,
252251
.c5:focus {

src/hooks/useMouseIntent.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export type {PositionProps, AbsoluteProps, FixedProps, RelativeProps, StickyProp
1919

2020
// Hooks
2121
export {default as useDetails} from './hooks/useDetails'
22-
export {default as useMouseIntent} from './hooks/useMouseIntent'
2322
export {default as useSafeTimeout} from './hooks/useSafeTimeout'
2423
export {useOnOutsideClick} from './hooks/useOnOutsideClick'
2524
export {useOpenAndCloseFocus} from './hooks/useOpenAndCloseFocus'

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7317,6 +7317,11 @@ flush-write-stream@^1.0.0:
73177317
inherits "^2.0.3"
73187318
readable-stream "^2.3.6"
73197319

7320+
7321+
version "5.2.0"
7322+
resolved "https://registry.yarnpkg.com/focus-visible/-/focus-visible-5.2.0.tgz#3a9e41fccf587bd25dcc2ef045508284f0a4d6b3"
7323+
integrity sha512-Rwix9pBtC1Nuy5wysTmKy+UjbDJpIfg8eHjw0rjZ1mX4GNLz1Bmd16uDpI3Gk1i70Fgcs8Csg2lPm8HULFg9DQ==
7324+
73207325
follow-redirects@^1.0.0:
73217326
version "1.13.2"
73227327
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147"

0 commit comments

Comments
 (0)