Skip to content

Commit

Permalink
fix(datagrid): skip focusing active cell if focus outside component (#…
Browse files Browse the repository at this point in the history
…1545)

## PR Checklist

Please check if your PR fulfills the following requirements:

- [ ] Tests for the changes have been added (for bug fixes / features)
- [ ] Docs have been added / updated (for bug fixes / features)
- [ ] If applicable, have a visual design approval

## PR Type

What kind of change does this PR introduce?

<!-- Please check the one that applies to this PR using "x". -->

- [X] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Documentation content changes
- [ ] Other... Please describe:

## What is the current behavior?

If you change the items inside datagrid trough outside filter and
previously it was clicked on any cell then the datagrid will steal the
focus.

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->

Issue Number: CDE-2273 #1542

## What is the new behavior?

Keep focus on the element

## Does this PR introduce a breaking change?

- [ ] Yes
- [X] No

<!-- If this PR contains a breaking change, please describe the impact
and migration path for existing applications below. -->

## Other information

(cherry picked from commit 7733e6b)
  • Loading branch information
dtsanevmw authored and github-actions[bot] committed Sep 5, 2024
1 parent 1e25bd6 commit e3f9579
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions projects/angular/src/data/datagrid/datagrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,14 @@ export class ClrDatagrid<T = any> implements AfterContentInit, AfterViewInit, On
}

// retain active cell when navigating with Up/Down Arrows, PageUp and PageDown buttons in virtual scroller
const active = this.keyNavigation.getActiveCell();

if (active) {
this.zone.runOutsideAngular(() => {
setTimeout(() => this.keyNavigation.setActiveCell(active));
});
if (this.hasVirtualScroller) {
const active = this.keyNavigation.getActiveCell();
const isFocusInsideDatagrid = this.datagrid.nativeElement.contains(document.activeElement);
if (active && isFocusInsideDatagrid) {
this.zone.runOutsideAngular(() => {
setTimeout(() => this.keyNavigation.setActiveCell(active));
});
}
}
})
);
Expand Down

0 comments on commit e3f9579

Please sign in to comment.