|
1 | | -import React, { useCallback, type PropsWithChildren } from 'react'; |
| 1 | +import React, { useCallback, useState, type PropsWithChildren } from 'react'; |
2 | 2 |
|
3 | 3 | import { |
4 | 4 | css, |
@@ -67,58 +67,75 @@ export default function ConnectionsFilterPopover({ |
67 | 67 | // Add future filters to the boolean below |
68 | 68 | const isActivated = filter.excludeInactive; |
69 | 69 |
|
| 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 | + |
70 | 83 | 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 | + </> |
123 | 140 | ); |
124 | 141 | } |
0 commit comments