Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Tucchhaa committed Jan 10, 2025
1 parent 3489c11 commit fe6405b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const ATTRIBUTES = {
};

export const ROWS_VIEW_CLASS = 'rowsview';
export const TABLE_CLASS = 'table';
export const EDIT_FORM_CLASS = 'edit-form';
export const GROUP_FOOTER_CLASS = 'group-footer';
export const ROW_CLASS = 'dx-row';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import {
REVERT_BUTTON_CLASS,
ROWS_VIEW,
ROWS_VIEW_CLASS,
TABLE_CLASS,
WIDGET_CLASS,
} from './const';
import { GridCoreKeyboardNavigationDom } from './dom';
Expand Down Expand Up @@ -332,25 +333,31 @@ export class KeyboardNavigationController extends modules.ViewController {
this._documentClickHandler = this._documentClickHandler || this.createAction((e) => {
const $target = $(e.event.target);

// if click was on the datagrid, but the target is no more presented in the DOM
if (!$target.get(0).isConnected && $target.closest('.dx-datagrid-table').length) {
// then prevent unfocusing the focused view
const tableSelector = `.${this.addWidgetPrefix(TABLE_CLASS)}`;
const rowsViewSelector = `.${this.addWidgetPrefix(ROWS_VIEW_CLASS)}`;
const editorOverlaySelector = `.${DROPDOWN_EDITOR_OVERLAY_CLASS}`;

// if click was on the datagrid table, but the target element is no more presented in the DOM
const keepFocus = !!$target.closest(tableSelector).length && !$target.get(0).isConnected;

if (keepFocus) {
e.event.preventDefault();
return;
}

const isCurrentRowsViewClick = this._isEventInCurrentGrid(e.event)
&& $target.closest(`.${this.addWidgetPrefix(ROWS_VIEW_CLASS)}`).length;
const isEditorOverlay = $target.closest(
`.${DROPDOWN_EDITOR_OVERLAY_CLASS}`,
).length;
const isColumnResizing = !!this._columnResizerController && this._columnResizerController.isResizing();
if (!isCurrentRowsViewClick && !isEditorOverlay && !isColumnResizing) {
const targetInsideFocusedView = this._focusedView
? $target.parents().filter(this._focusedView.element()).length > 0
: false;
const isRowsViewClick = this._isEventInCurrentGrid(e.event) && !!$target.closest(rowsViewSelector).length;
const isEditorOverlayClick = !!$target.closest(editorOverlaySelector).length;
const isColumnResizing = !!this._columnResizerController?.isResizing();

if (!isRowsViewClick && !isEditorOverlayClick && !isColumnResizing) {
const outsideFocusedView = this._focusedView
? $target.closest(this._focusedView.element()).length === 0
: true;

if (outsideFocusedView) {
this._resetFocusedCell(true);
}

!targetInsideFocusedView && this._resetFocusedCell(true);
this._resetFocusedView();
}
});
Expand Down

0 comments on commit fe6405b

Please sign in to comment.