Skip to content

Commit 65beec5

Browse files
committed
Control tooltip to avoid it showing when closing popover
1 parent b8f783f commit 65beec5

File tree

1 file changed

+70
-53
lines changed

1 file changed

+70
-53
lines changed

packages/compass-sidebar/src/components/connections-filter-popover.tsx

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useCallback, type PropsWithChildren } from 'react';
1+
import React, { useCallback, useState, type PropsWithChildren } from 'react';
22

33
import {
44
css,
@@ -67,58 +67,75 @@ export default function ConnectionsFilterPopover({
6767
// Add future filters to the boolean below
6868
const isActivated = filter.excludeInactive;
6969

70+
// Manually handling the tooltip state instead of supplying a trigger
71+
// we do this to avoid the tooltip from rendering when the popover is open
72+
// and when the IconButton regains focus as the
73+
const [isTooltipOpen, setTooltipOpen] = useState(false);
74+
const handleButtonMouseEnter = useCallback(
75+
() => setTooltipOpen(true),
76+
[setTooltipOpen]
77+
);
78+
const handleButtonMouseLeave = useCallback(
79+
() => setTooltipOpen(false),
80+
[setTooltipOpen]
81+
);
82+
7083
return (
71-
<InteractivePopover
72-
open={open}
73-
setOpen={setOpen}
74-
containerClassName={containerStyles}
75-
hideCloseButton
76-
trigger={({ onClick, children, ref }) => (
77-
<>
78-
<Tooltip
79-
align="right"
80-
trigger={
81-
<IconButton
82-
onClick={onClick}
83-
active={open}
84-
aria-label="Filter connections"
85-
ref={ref as React.Ref<unknown>}
86-
>
87-
<Icon glyph="Filter" />
88-
{isActivated && (
89-
<svg
90-
className={activatedIndicatorStyles}
91-
width="6"
92-
height="6"
93-
viewBox="0 0 6 6"
94-
fill="none"
95-
xmlns="http://www.w3.org/2000/svg"
96-
>
97-
<circle cx="3" cy="3" r="3" fill={palette.blue.base} />
98-
</svg>
99-
)}
100-
</IconButton>
101-
}
102-
>
103-
Filter connections
104-
</Tooltip>
105-
{children}
106-
</>
107-
)}
108-
>
109-
<Overline>Filter Options</Overline>
110-
<div className={groupStyles}>
111-
<Toggle
112-
id={excludeInactiveToggleId}
113-
aria-labelledby={excludeInactiveLabelId}
114-
checked={filter.excludeInactive}
115-
onChange={onExcludeInactiveChange}
116-
size="small"
117-
/>
118-
<Label htmlFor={excludeInactiveToggleId} id={excludeInactiveLabelId}>
119-
Show only active connections
120-
</Label>
121-
</div>
122-
</InteractivePopover>
84+
<>
85+
<Tooltip
86+
align="right"
87+
open={isTooltipOpen && !open}
88+
setOpen={setTooltipOpen}
89+
>
90+
Filter connections
91+
</Tooltip>
92+
<InteractivePopover
93+
open={open}
94+
setOpen={setOpen}
95+
containerClassName={containerStyles}
96+
hideCloseButton
97+
trigger={({ onClick, children, ref }) => (
98+
<>
99+
<IconButton
100+
onClick={onClick}
101+
onMouseEnter={handleButtonMouseEnter}
102+
onMouseLeave={handleButtonMouseLeave}
103+
active={open}
104+
aria-label="Filter connections"
105+
ref={ref as React.Ref<unknown>}
106+
>
107+
<Icon glyph="Filter" />
108+
{isActivated && (
109+
<svg
110+
className={activatedIndicatorStyles}
111+
width="6"
112+
height="6"
113+
viewBox="0 0 6 6"
114+
fill="none"
115+
xmlns="http://www.w3.org/2000/svg"
116+
>
117+
<circle cx="3" cy="3" r="3" fill={palette.blue.base} />
118+
</svg>
119+
)}
120+
</IconButton>
121+
{children}
122+
</>
123+
)}
124+
>
125+
<Overline>Filter Options</Overline>
126+
<div className={groupStyles}>
127+
<Toggle
128+
id={excludeInactiveToggleId}
129+
aria-labelledby={excludeInactiveLabelId}
130+
checked={filter.excludeInactive}
131+
onChange={onExcludeInactiveChange}
132+
size="small"
133+
/>
134+
<Label htmlFor={excludeInactiveToggleId} id={excludeInactiveLabelId}>
135+
Show only active connections
136+
</Label>
137+
</div>
138+
</InteractivePopover>
139+
</>
123140
);
124141
}

0 commit comments

Comments
 (0)