Skip to content

Commit 4f09341

Browse files
committed
Allow removing the attachment without closing the widget
1 parent 7bdf689 commit 4f09341

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/widget.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,32 @@ export class FloatingInputWidget extends ReactWidget {
169169
}
170170

171171
private _onDocumentClick(event: Event): void {
172-
if (!this.node.contains(event.target as Node)) {
172+
if (this.isDisposed) {
173+
return;
174+
}
175+
176+
const target = event.target as HTMLElement;
177+
178+
// Check if the target is still in the DOM.
179+
if (!document.contains(target)) {
180+
return;
181+
}
182+
183+
// Check if it's a MUI Portal element (Popper, Menu, etc.), which can be attached
184+
// to the body and not to the widget (for example the title of a button).
185+
const isMuiPortal =
186+
target.closest('[data-mui-portal]') !== null ||
187+
target.closest('.MuiPopper-root') !== null ||
188+
target.closest('.MuiPopover-root') !== null ||
189+
target.closest('.MuiTooltip-popper') !== null ||
190+
target.closest('.MuiDialog-root') !== null ||
191+
target.closest('[role="presentation"]') !== null;
192+
193+
if (isMuiPortal) {
194+
return;
195+
}
196+
197+
if (!this.node.contains(target)) {
173198
this.dispose();
174199
}
175200
}

0 commit comments

Comments
 (0)