@@ -24,6 +24,7 @@ import {
2424import { isDeferred , isDefined , isEmptyObject } from '@js/core/utils/type' ;
2525import * as accessibility from '@js/ui/shared/accessibility' ;
2626import { focused } from '@js/ui/widget/selectors' ;
27+ import { isElementInDom } from '@ts/core/utils/m_dom' ;
2728import type { AdaptiveColumnsController } from '@ts/grids/grid_core/adaptivity/m_adaptivity' ;
2829import type { DataController } from '@ts/grids/grid_core/data_controller/m_data_controller' ;
2930import type { EditingController } from '@ts/grids/grid_core/editing/m_editing' ;
@@ -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' ;
@@ -331,18 +333,32 @@ export class KeyboardNavigationController extends modules.ViewController {
331333
332334 this . _documentClickHandler = this . _documentClickHandler || this . createAction ( ( e ) => {
333335 const $target = $ ( e . event . target ) ;
334- const isCurrentRowsViewClick = this . _isEventInCurrentGrid ( e . event )
335- && $target . closest ( `.${ this . addWidgetPrefix ( ROWS_VIEW_CLASS ) } ` ) . length ;
336- const isEditorOverlay = $target . closest (
337- `.${ DROPDOWN_EDITOR_OVERLAY_CLASS } ` ,
338- ) . length ;
339- const isColumnResizing = ! ! this . _columnResizerController && this . _columnResizerController . isResizing ( ) ;
340- if ( ! isCurrentRowsViewClick && ! isEditorOverlay && ! isColumnResizing ) {
341- const targetInsideFocusedView = this . _focusedView
342- ? $target . parents ( ) . filter ( this . _focusedView . element ( ) ) . length > 0
343- : false ;
344-
345- ! targetInsideFocusedView && this . _resetFocusedCell ( true ) ;
336+
337+ const tableSelector = `.${ this . addWidgetPrefix ( TABLE_CLASS ) } ` ;
338+ const rowsViewSelector = `.${ this . addWidgetPrefix ( ROWS_VIEW_CLASS ) } ` ;
339+ const editorOverlaySelector = `.${ DROPDOWN_EDITOR_OVERLAY_CLASS } ` ;
340+
341+ // if click was on the datagrid table, but the target element is no more presented in the DOM
342+ const needKeepFocus = ! ! $target . closest ( tableSelector ) . length && ! isElementInDom ( $target ) ;
343+
344+ if ( needKeepFocus ) {
345+ e . event . preventDefault ( ) ;
346+ return ;
347+ }
348+
349+ const isRowsViewClick = this . _isEventInCurrentGrid ( e . event ) && ! ! $target . closest ( rowsViewSelector ) . length ;
350+ const isEditorOverlayClick = ! ! $target . closest ( editorOverlaySelector ) . length ;
351+ const isColumnResizing = ! ! this . _columnResizerController ?. isResizing ( ) ;
352+
353+ if ( ! isRowsViewClick && ! isEditorOverlayClick && ! isColumnResizing ) {
354+ const isClickOutsideFocusedView = this . _focusedView
355+ ? $target . closest ( this . _focusedView . element ( ) ) . length === 0
356+ : true ;
357+
358+ if ( isClickOutsideFocusedView ) {
359+ this . _resetFocusedCell ( true ) ;
360+ }
361+
346362 this . _resetFocusedView ( ) ;
347363 }
348364 } ) ;
0 commit comments