Skip to content

Commit 6734075

Browse files
committed
Fix events race condition preventing BlockToolbar closing
1 parent a6be592 commit 6734075

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/components/Toolbar/BlockToolbar/BlockToolbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ const BlockToolbar = ({
144144
<div className="Draftail-BlockToolbar" ref={toolbarRef}>
145145
<Tooltip
146146
shouldOpen={visible}
147-
onHide={() => setVisible(false)}
147+
onClickOutside={() => setVisible(false)}
148148
placement={comboPlacement}
149149
zIndex={tooltipZIndex}
150150
showBackdrop={showBackdrop}
@@ -179,7 +179,7 @@ const BlockToolbar = ({
179179
className="Draftail-BlockToolbar__trigger"
180180
style={{ top: focusOffset }}
181181
aria-label={triggerLabel}
182-
onClick={() => setVisible(true)}
182+
onClick={() => setVisible(!visible)}
183183
>
184184
{triggerIcon}
185185
</button>

src/components/Tooltip/Tooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface TooltipProps {
6868
zIndex?: number;
6969
placement?: TooltipPlacement;
7070
onHide?: () => void;
71+
onClickOutside?: () => void;
7172
onMount?: (instance: PopperInstance) => void;
7273
}
7374

@@ -80,6 +81,7 @@ const Tooltip = ({
8081
zIndex = 100,
8182
placement = "top" as TooltipPlacement,
8283
onHide,
84+
onClickOutside,
8385
onMount,
8486
}: TooltipProps) => {
8587
const parentRef = useRef<HTMLDivElement>(null);
@@ -121,7 +123,7 @@ const Tooltip = ({
121123
visible={visible}
122124
interactive
123125
onHide={onHide}
124-
onClickOutside={onHide}
126+
onClickOutside={onClickOutside || onHide}
125127
onMount={onMount}
126128
placement={placement}
127129
maxWidth="100%"

0 commit comments

Comments
 (0)