Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(datagrid): prevent scroll on details cell click #1608

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
* The full license information can be found in LICENSE in the root directory of this project.
*/

import { Injectable, NgZone, OnDestroy } from '@angular/core';
import { Injectable, NgZone, OnDestroy, reflectComponentType } from '@angular/core';
import { fromEvent, Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';

import { ClrDatagridRowDetail } from '../datagrid-row-detail';

export function getTabableItems(el: HTMLElement) {
const tabableSelector = [
'a[href]',
Expand Down Expand Up @@ -164,11 +166,19 @@ export class KeyNavigationGridController implements OnDestroy {
const items = getTabableItems(activeCell);
const item = activeCell.getAttribute('role') !== 'columnheader' && items[0] ? items[0] : activeCell;

if (!this.skipItemFocus) {
if (!this.skipItemFocus && !this.isDetailsCell(activeCell)) {
item.focus();
}
}

private isDetailsCell(cell: HTMLElement) {
const detailRowElementName = reflectComponentType(ClrDatagridRowDetail).selector.toLowerCase();
return (
cell.tagName.toLowerCase() === detailRowElementName ||
cell.parentElement.tagName.toLowerCase() === detailRowElementName
);
}

private getNextItemCoordinate(e: any) {
let currentCell = this.cells ? Array.from(this.cells).find(i => i.getAttribute('tabindex') === '0') : null;
if (e.code === 'Tab') {
Expand Down
Loading