Skip to content

Commit ea40238

Browse files
fix: check if CSS.supports() is available
1 parent 65cb02d commit ea40238

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/components/TooltipController/TooltipController.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
} from 'components/Tooltip/TooltipTypes'
1313
import { useTooltip } from 'components/TooltipProvider'
1414
import { TooltipContent } from 'components/TooltipContent'
15+
import cssSupports from 'utils/css-supports'
1516
import type { ITooltipController } from './TooltipControllerTypes'
1617

1718
const TooltipController = ({
@@ -274,15 +275,15 @@ const TooltipController = ({
274275
// eslint-disable-next-line no-console
275276
console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.')
276277
}
277-
if (border && !CSS.supports('border', `${border}`)) {
278+
if (border && !cssSupports('border', `${border}`)) {
278279
// eslint-disable-next-line no-console
279280
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`)
280281
}
281282
if (style?.opacity) {
282283
// eslint-disable-next-line no-console
283284
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.')
284285
}
285-
if (opacity && !CSS.supports('opacity', `${opacity}`)) {
286+
if (opacity && !cssSupports('opacity', `${opacity}`)) {
286287
// eslint-disable-next-line no-console
287288
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`)
288289
}

src/utils/css-supports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const cssSupports = (property: string, value: string): boolean => {
2+
const hasCssSupports = 'CSS' in window && 'supports' in window.CSS
3+
if (!hasCssSupports) {
4+
return true
5+
}
6+
return window.CSS.supports(property, value)
7+
}
8+
9+
export default cssSupports

0 commit comments

Comments
 (0)