File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments