@@ -6,6 +6,7 @@ import type { dxElementWrapper } from '@js/core/renderer';
66import $ from '@js/core/renderer' ;
77import browser from '@js/core/utils/browser' ;
88import { Deferred , when } from '@js/core/utils/deferred' ;
9+ import { isElementInDom } from '@js/core/utils/dom' ;
910import {
1011 getHeight ,
1112 getOuterHeight ,
@@ -71,6 +72,7 @@ import {
7172 REVERT_BUTTON_CLASS ,
7273 ROWS_VIEW ,
7374 ROWS_VIEW_CLASS ,
75+ TABLE_CLASS ,
7476 WIDGET_CLASS ,
7577} from './const' ;
7678import { GridCoreKeyboardNavigationDom } from './dom' ;
@@ -307,18 +309,32 @@ export class KeyboardNavigationController extends modules.ViewController {
307309
308310 this . _documentClickHandler = this . _documentClickHandler || this . createAction ( ( e ) => {
309311 const $target = $ ( e . event . target ) ;
310- const isCurrentRowsViewClick = this . _isEventInCurrentGrid ( e . event )
311- && $target . closest ( `.${ this . addWidgetPrefix ( ROWS_VIEW_CLASS ) } ` ) . length ;
312- const isEditorOverlay = $target . closest (
313- `.${ DROPDOWN_EDITOR_OVERLAY_CLASS } ` ,
314- ) . length ;
315- const isColumnResizing = ! ! this . _columnResizerController && this . _columnResizerController . isResizing ( ) ;
316- if ( ! isCurrentRowsViewClick && ! isEditorOverlay && ! isColumnResizing ) {
317- const targetInsideFocusedView = this . _focusedView
318- ? $target . parents ( ) . filter ( this . _focusedView . element ( ) ) . length > 0
319- : false ;
320-
321- ! targetInsideFocusedView && this . _resetFocusedCell ( true ) ;
312+
313+ const tableSelector = `.${ this . addWidgetPrefix ( TABLE_CLASS ) } ` ;
314+ const rowsViewSelector = `.${ this . addWidgetPrefix ( ROWS_VIEW_CLASS ) } ` ;
315+ const editorOverlaySelector = `.${ DROPDOWN_EDITOR_OVERLAY_CLASS } ` ;
316+
317+ // if click was on the datagrid table, but the target element is no more presented in the DOM
318+ const needKeepFocus = ! ! $target . closest ( tableSelector ) . length && ! isElementInDom ( $target ) ;
319+
320+ if ( needKeepFocus ) {
321+ e . event . preventDefault ( ) ;
322+ return ;
323+ }
324+
325+ const isRowsViewClick = this . _isEventInCurrentGrid ( e . event ) && ! ! $target . closest ( rowsViewSelector ) . length ;
326+ const isEditorOverlayClick = ! ! $target . closest ( editorOverlaySelector ) . length ;
327+ const isColumnResizing = ! ! this . _columnResizerController ?. isResizing ( ) ;
328+
329+ if ( ! isRowsViewClick && ! isEditorOverlayClick && ! isColumnResizing ) {
330+ const isClickOutsideFocusedView = this . _focusedView
331+ ? $target . closest ( this . _focusedView . element ( ) ) . length === 0
332+ : true ;
333+
334+ if ( isClickOutsideFocusedView ) {
335+ this . _resetFocusedCell ( true ) ;
336+ }
337+
322338 this . _resetFocusedView ( ) ;
323339 }
324340 } ) ;
0 commit comments