Skip to content

Commit

Permalink
[components] Disable interaction for Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored and rexxars committed Oct 6, 2020
1 parent c0f4460 commit 50a0039
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/@sanity/components/src/tooltip/tooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.root {
z-index: var(--zindex-popover + 1);
pointer-events: none;
}

.card {
Expand Down
23 changes: 3 additions & 20 deletions packages/@sanity/components/src/tooltip/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import classNames from 'classnames'
import {Portal} from 'part:@sanity/components/portal'
import React, {useCallback, useEffect, useRef, useState} from 'react'
import React, {useCallback, useEffect, useState} from 'react'
import {usePopper} from 'react-popper'
import {TooltipArrow} from './tooltipArrow'
import {useTooltip} from './hooks'
Expand Down Expand Up @@ -32,7 +32,6 @@ export function Tooltip(
...restProps
} = props
const ctx = useTooltip()
const leaveRafRef = useRef<number | null>(null)
const [referenceElement, setReferenceElement] = useState<HTMLElement | null>(null)
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null)
const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null)
Expand Down Expand Up @@ -60,26 +59,12 @@ export function Tooltip(
}
]
})

const {forceUpdate} = popper

const [isOpen, setIsOpen] = useState(false)

const handleBlur = useCallback(() => setIsOpen(false), [])

const handleFocus = useCallback(() => setIsOpen(true), [])

const handleMouseEnter = useCallback(() => {
if (leaveRafRef.current !== null) {
cancelAnimationFrame(leaveRafRef.current)
}

setIsOpen(true)
}, [])

const handleMouseLeave = useCallback(() => {
leaveRafRef.current = requestAnimationFrame(() => setIsOpen(false))
}, [])
const handleMouseEnter = useCallback(() => setIsOpen(true), [])
const handleMouseLeave = useCallback(() => setIsOpen(false), [])

useEffect(() => {
if (forceUpdate) forceUpdate()
Expand All @@ -94,8 +79,6 @@ export function Tooltip(
{...restProps}
className={classNames(styles.root, className)}
data-tone={tone}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
ref={setPopperElement}
style={popper.styles.popper}
{...popper.attributes.popper}
Expand Down
1 change: 0 additions & 1 deletion packages/@sanity/components/src/tooltip/tooltipArrow.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

.root {
position: absolute;
pointer-events: none;
width: 15px;
height: 15px;
fill: none;
Expand Down

0 comments on commit 50a0039

Please sign in to comment.