Make sure web tooltip closes on interaction with target
This commit is contained in:
@@ -13,10 +13,12 @@ import {Text} from '#/components/Typography'
|
|||||||
|
|
||||||
type TooltipContextType = {
|
type TooltipContextType = {
|
||||||
position: 'top' | 'bottom'
|
position: 'top' | 'bottom'
|
||||||
|
onVisibleChange: (open: boolean) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const TooltipContext = createContext<TooltipContextType>({
|
const TooltipContext = createContext<TooltipContextType>({
|
||||||
position: 'bottom',
|
position: 'bottom',
|
||||||
|
onVisibleChange: () => {},
|
||||||
})
|
})
|
||||||
|
|
||||||
export function Outer({
|
export function Outer({
|
||||||
@@ -30,7 +32,10 @@ export function Outer({
|
|||||||
visible: boolean
|
visible: boolean
|
||||||
onVisibleChange: (visible: boolean) => void
|
onVisibleChange: (visible: boolean) => void
|
||||||
}) {
|
}) {
|
||||||
const ctx = useMemo(() => ({position}), [position])
|
const ctx = useMemo(
|
||||||
|
() => ({position, onVisibleChange}),
|
||||||
|
[position, onVisibleChange],
|
||||||
|
)
|
||||||
return (
|
return (
|
||||||
<Popover.Root open={visible} onOpenChange={onVisibleChange}>
|
<Popover.Root open={visible} onOpenChange={onVisibleChange}>
|
||||||
<TooltipContext.Provider value={ctx}>{children}</TooltipContext.Provider>
|
<TooltipContext.Provider value={ctx}>{children}</TooltipContext.Provider>
|
||||||
@@ -54,7 +59,7 @@ export function Content({
|
|||||||
label: string
|
label: string
|
||||||
}) {
|
}) {
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {position} = useContext(TooltipContext)
|
const {position, onVisibleChange} = useContext(TooltipContext)
|
||||||
return (
|
return (
|
||||||
<Popover.Portal>
|
<Popover.Portal>
|
||||||
<Popover.Content
|
<Popover.Content
|
||||||
@@ -63,6 +68,7 @@ export function Content({
|
|||||||
side={position}
|
side={position}
|
||||||
sideOffset={4}
|
sideOffset={4}
|
||||||
collisionPadding={MIN_EDGE_SPACE}
|
collisionPadding={MIN_EDGE_SPACE}
|
||||||
|
onInteractOutside={() => onVisibleChange(false)}
|
||||||
style={flatten([
|
style={flatten([
|
||||||
a.rounded_sm,
|
a.rounded_sm,
|
||||||
select(t.name, {
|
select(t.name, {
|
||||||
|
|||||||
Reference in New Issue
Block a user