fix: switch to native :focus-visible for firefox 88+ (#2039)

This commit is contained in:
Nolan Lawson 2021-05-11 21:40:40 -07:00 committed by GitHub
parent f9ac31465d
commit 3971f9a636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View file

@ -1,7 +1,7 @@
import { thunk } from './thunk' import { thunk } from './thunk'
import { supportsSelector } from './supportsSelector' import { supportsSelector } from './supportsSelector'
import { isFirefox } from './userAgent/isFirefox' import { isFirefoxPre88 } from './userAgent/isFirefoxPre88'
// TODO: remove the Firefox check once this bug is fixed // Firefox pre-88 had a focus-visible bug:
// https://bugzilla.mozilla.org/show_bug.cgi?id=1699154 // https://bugzilla.mozilla.org/show_bug.cgi?id=1699154
export const supportsFocusVisible = thunk(() => (!isFirefox() && supportsSelector(':focus-visible'))) export const supportsFocusVisible = thunk(() => (!isFirefoxPre88() && supportsSelector(':focus-visible')))

View file

@ -1,3 +1,5 @@
export function isFirefox () { import { thunk } from '../thunk'
return typeof InstallTrigger !== 'undefined' // https://stackoverflow.com/a/9851769/680742
} export const isFirefox = thunk(() => {
return process.browser && typeof InstallTrigger !== 'undefined' // https://stackoverflow.com/a/9851769/680742
})

View file

@ -0,0 +1,17 @@
import { isFirefox } from './isFirefox'
import { thunk } from '../thunk'
export const isFirefoxPre88 = thunk(() => {
if (!isFirefox()) {
return false
}
try {
// https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/88#javascript
// https://github.com/tc39/proposal-regexp-match-indices
// eslint-disable-next-line no-invalid-regexp,prefer-regex-literals
RegExp('', 'd')
return false
} catch (e) {
return true
}
})