Skip to content

Check if CSS.supports() is available #1117

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

Merged
merged 2 commits into from
Nov 13, 2023
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: 3 additions & 2 deletions src/components/TooltipController/TooltipController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
} from 'components/Tooltip/TooltipTypes'
import { useTooltip } from 'components/TooltipProvider'
import { TooltipContent } from 'components/TooltipContent'
import cssSupports from 'utils/css-supports'
import type { ITooltipController } from './TooltipControllerTypes'

const TooltipController = ({
Expand Down Expand Up @@ -274,15 +275,15 @@ const TooltipController = ({
// eslint-disable-next-line no-console
console.warn('[react-tooltip] Do not set `style.border`. Use `border` prop instead.')
}
if (border && !CSS.supports('border', `${border}`)) {
if (border && !cssSupports('border', `${border}`)) {
// eslint-disable-next-line no-console
console.warn(`[react-tooltip] "${border}" is not a valid \`border\`.`)
}
if (style?.opacity) {
// eslint-disable-next-line no-console
console.warn('[react-tooltip] Do not set `style.opacity`. Use `opacity` prop instead.')
}
if (opacity && !CSS.supports('opacity', `${opacity}`)) {
if (opacity && !cssSupports('opacity', `${opacity}`)) {
// eslint-disable-next-line no-console
console.warn(`[react-tooltip] "${opacity}" is not a valid \`opacity\`.`)
}
Expand Down
6 changes: 6 additions & 0 deletions src/utils/css-supports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const cssSupports = (property: string, value: string): boolean => {
const hasCssSupports = 'CSS' in window && 'supports' in window.CSS
return hasCssSupports ? window.CSS.supports(property, value) : true
}

export default cssSupports