Skip to content

Commit 51ebcf7

Browse files
authored
fix: suppress tooltip on dialog close to prevent unwanted tooltip flash (#196)
When the native <dialog> closes, focus returns to the trigger button, causing the cosmoz-tooltip to show briefly. This adds a temporary disabled state (500ms) on the tooltip after dialog close to suppress this unwanted behavior. Bumps @neovici/cosmoz-tooltip to ^1.1.0 for the new disabled attribute.
1 parent f60ce71 commit 51ebcf7

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"@neovici/cosmoz-icons": "^1.5.0",
9292
"@neovici/cosmoz-input": "^5.0.0",
9393
"@neovici/cosmoz-tokens": "^3.2.1",
94-
"@neovici/cosmoz-tooltip": "^1.0.2",
94+
"@neovici/cosmoz-tooltip": "^1.1.0",
9595
"@neovici/cosmoz-tree": "^3.6.1",
9696
"@neovici/cosmoz-utils": "^6.8.1",
9797
"@pionjs/pion": "^2.12.0",

src/cosmoz-treenode-button-view.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const CosmozNodeButtonView = ({
5858
searchDebounceTimeout = 500,
5959
}: ButtonViewProps) => {
6060
const dialogRef = useRef<ButtonViewDialog | null>(null);
61+
const tooltipTimeoutRef = useRef<ReturnType<typeof setTimeout>>();
6162

6263
// nodePath is the single source of truth - external two-way binding
6364
const [nodePath, setNodePath] = useProperty<string>('nodePath', '');
@@ -68,6 +69,10 @@ const CosmozNodeButtonView = ({
6869
// Track highlighted node path from navigator for Select button
6970
const [highlightedNodePath, setHighlightedNodePath] = useState<string>('');
7071

72+
// Temporarily suppress tooltip after dialog close to prevent
73+
// it from showing when focus returns to the button
74+
const [tooltipDisabled, setTooltipDisabled] = useState(false);
75+
7176
// nodesOnNodePath derived from nodePath + tree
7277
const nodesOnNodePath = useMemo(
7378
() => getTreePathParts(nodePath, tree),
@@ -101,7 +106,15 @@ const CosmozNodeButtonView = ({
101106

102107
const onOpen = () => setOpened(true);
103108

104-
const onClose = () => setOpened(false);
109+
const onClose = () => {
110+
setOpened(false);
111+
setTooltipDisabled(true);
112+
clearTimeout(tooltipTimeoutRef.current);
113+
tooltipTimeoutRef.current = setTimeout(
114+
() => setTooltipDisabled(false),
115+
500,
116+
);
117+
};
105118

106119
useKeyDown('Escape', onClose);
107120

@@ -161,6 +174,7 @@ const CosmozNodeButtonView = ({
161174
placement="right"
162175
.description=${buttonLabel}
163176
.delay=${1000}
177+
.disabled=${tooltipDisabled}
164178
>
165179
<cosmoz-button
166180
variant="secondary"

0 commit comments

Comments
 (0)