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

Remove useMouseIntent in favor of focus-visible #1157

Merged
merged 4 commits into from
Apr 15, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/heavy-trainers-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/components": major
---

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.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@types/styled-system__theme-get": "5.0.1",
"classnames": "^2.2.5",
"deepmerge": "4.2.2",
"focus-visible": "5.2.0",
"polished": "3.5.2",
"react-is": "16.10.2",
"styled-system": "5.1.2"
Expand Down
33 changes: 17 additions & 16 deletions src/BaseStyles.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import React from 'react'
import styled, {createGlobalStyle} from 'styled-components'
import {COMMON, SystemCommonProps, SystemTypographyProps, TYPOGRAPHY} from './constants'
import useMouseIntent from './hooks/useMouseIntent'
import {ComponentProps} from './utils/types'

const GlobalStyle = createGlobalStyle`
* { box-sizing: border-box; }
body { margin: 0; }
table { border-collapse: collapse; }
body.intent-mouse {
[role="button"]:focus,
[role="tabpanel"][tabindex="0"]:focus,
button:focus,
summary:focus,
a:focus {
outline: none;
box-shadow: none;
}

[tabindex="0"]:focus,
details-dialog:focus {
outline: none;
}

[role="button"]:focus:not(:focus-visible):not(.focus-visible),
[role="tabpanel"][tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
button:focus:not(:focus-visible):not(.focus-visible),
summary:focus:not(:focus-visible):not(.focus-visible),
a:focus:not(:focus-visible):not(.focus-visible) {
outline: none;
box-shadow: none;
}

[tabindex="0"]:focus:not(:focus-visible):not(.focus-visible),
details-dialog:focus:not(:focus-visible):not(.focus-visible) {
outline: none;
}
`

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

function BaseStyles(props: BaseStylesProps) {
const {children, ...rest} = props
useMouseIntent()

// load polyfill for :focus-visible
require('focus-visible')
dgreif marked this conversation as resolved.
Show resolved Hide resolved

return (
<Base {...rest} data-portal-root>
<GlobalStyle />
Expand Down
1 change: 0 additions & 1 deletion src/SelectMenu/SelectMenuItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export const listItemStyles = css`

// can hover states
@media (hover: hover) {
body:not(.intent-mouse) .SelectMenu-item:focus,
Copy link
Member Author

Choose a reason for hiding this comment

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

I can't find any instances of the .SelectMenu-item class being used. Possible I overlooked it, but I think this can be removed at this point.

&:hover,
&:active,
&:focus {
Expand Down
1 change: 0 additions & 1 deletion src/__tests__/__snapshots__/SelectMenu.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ exports[`SelectMenu right-aligned modal has right: 0px 1`] = `
}

@media (hover:hover) {
.c5 body:not(.intent-mouse) .SelectMenu-item:focus,
.c5:hover,
.c5:active,
.c5:focus {
Expand Down
39 changes: 0 additions & 39 deletions src/hooks/useMouseIntent.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export type {PositionProps, AbsoluteProps, FixedProps, RelativeProps, StickyProp

// Hooks
export {default as useDetails} from './hooks/useDetails'
export {default as useMouseIntent} from './hooks/useMouseIntent'
dgreif marked this conversation as resolved.
Show resolved Hide resolved
export {default as useSafeTimeout} from './hooks/useSafeTimeout'
export {useOnOutsideClick} from './hooks/useOnOutsideClick'
export {useOpenAndCloseFocus} from './hooks/useOpenAndCloseFocus'
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7317,6 +7317,11 @@ flush-write-stream@^1.0.0:
inherits "^2.0.3"
readable-stream "^2.3.6"

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.0.0:
version "1.13.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.2.tgz#dd73c8effc12728ba5cf4259d760ea5fb83e3147"
Expand Down