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
…backport to 16.x) (#1546)

Backport 7733e6b from #1545. <br> ## 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?

&lt;!-- Please check the one that applies to this PR using
&quot;x&quot;. --&gt;

- [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.

&lt;!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. --&gt;

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

&lt;!-- If this PR contains a breaking change, please describe the
impact and migration path for existing applications below. --&gt;

## Other information

Co-authored-by: Daniel Tsanev <127101685+dtsanevmw@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and dtsanevmw authored Sep 5, 2024
1 parent 1e25bd6 commit 2d6c96a
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 2d6c96a

Please sign in to comment.