Skip to content

Commit

Permalink
fix(components/ag-grid): datepicker cell editor should handle refresh…
Browse files Browse the repository at this point in the history
  • Loading branch information
johnhwhite authored Jan 27, 2025
1 parent 5b6024f commit a97c246
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ describe('SkyCellEditorDatepickerComponent', () => {
]);
let cellEditorParams: Partial<SkyCellEditorDatepickerParams>;
let column: AgColumn;
let gridCell: HTMLElement;
const dateString = '01/01/2019';
const date = new Date(dateString);
const rowNode = new RowNode({} as BeanCollection);
Expand All @@ -464,6 +465,7 @@ describe('SkyCellEditorDatepickerComponent', () => {
'col',
true,
);
gridCell = document.createElement('div');

cellEditorParams = {
api,
Expand All @@ -472,6 +474,7 @@ describe('SkyCellEditorDatepickerComponent', () => {
node: rowNode,
colDef: {},
cellStartedEdit: true,
eGridCell: gridCell,
};
});

Expand All @@ -494,6 +497,24 @@ describe('SkyCellEditorDatepickerComponent', () => {
expect(input.focus).toHaveBeenCalled();
}));

it('should respond to reset focus', fakeAsync(() => {
datepickerEditorComponent.agInit(
cellEditorParams as SkyCellEditorDatepickerParams,
);
datepickerEditorFixture.detectChanges();
const input = datepickerEditorNativeElement.querySelector(
'input',
) as HTMLInputElement;
spyOn(input, 'focus');
datepickerEditorComponent.onFocusOut({
relatedTarget: gridCell,
} as unknown as FocusEvent);
tick();

expect(input).toBeVisible();
expect(input.focus).toHaveBeenCalled();
}));

describe('cellStartedEdit is true', () => {
it('does not select the input value if Backspace triggers the edit', fakeAsync(() => {
datepickerEditorComponent.agInit({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ export class SkyAgGridCellEditorDatepickerComponent

@HostListener('focusout', ['$event'])
public onFocusOut(event: FocusEvent): void {
if (event.target === this.datepickerInput?.nativeElement) {
if (
event.relatedTarget &&
event.relatedTarget === this.#params?.eGridCell
) {
// If focus is being set to the grid cell, schedule focus on the datepicker input.
// This happens when the refreshCells API is called.
this.afterGuiAttached();
} else if (event.target === this.datepickerInput?.nativeElement) {
this.#stopEditingOnBlur();
}
}
Expand Down

0 comments on commit a97c246

Please sign in to comment.