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(date-range): projected input focus restore on consecutive close #14951

Merged
merged 4 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
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 @@ -1157,7 +1157,7 @@ describe('IgxDateRangePicker', () => {
expect(dateRange.opening.emit).toHaveBeenCalledTimes(1);
expect(dateRange.opened.emit).toHaveBeenCalledTimes(1);

const calendarWrapper = document.getElementsByClassName('igx-calendar__wrapper')[0];
let calendarWrapper = document.getElementsByClassName('igx-calendar__wrapper')[0];
expect(calendarWrapper.contains(document.activeElement))
.withContext('focus should move to calendar for KB nav')
.toBeTrue();
Expand All @@ -1173,6 +1173,24 @@ describe('IgxDateRangePicker', () => {
.withContext('focus should return to the picker input')
.toBeTrue();
expect(dateRange.isFocused).toBeTrue();

// reopen and close again
UIInteractions.triggerEventHandlerKeyDown('ArrowDown', range, true);
tick(DEBOUNCE_TIME * 2);
fixture.detectChanges();

calendarWrapper = document.getElementsByClassName('igx-calendar__wrapper')[0];
expect(calendarWrapper.contains(document.activeElement))
.withContext('focus should move to calendar for KB nav')
.toBeTrue();
UIInteractions.triggerKeyDownEvtUponElem('ArrowUp', calendarWrapper, true, true);
tick();
fixture.detectChanges();

expect(startInput.nativeElement.contains(document.activeElement))
.withContext('focus should return to the picker input')
.toBeTrue();
expect(dateRange.isFocused).toBeTrue();
}));

it('should toggle the calendar with ALT + DOWN/UP ARROW key - dialog mode', fakeAsync(() => {
Expand Down Expand Up @@ -1215,7 +1233,7 @@ describe('IgxDateRangePicker', () => {
fixture.detectChanges();
expect(dateRange.collapsed).toBeFalsy();

const calendarWrapper = document.getElementsByClassName('igx-calendar__wrapper')[0];
let calendarWrapper = document.getElementsByClassName('igx-calendar__wrapper')[0];
expect(calendarWrapper.contains(document.activeElement))
.withContext('focus should move to calendar for KB nav')
.toBeTrue();
Expand All @@ -1232,6 +1250,24 @@ describe('IgxDateRangePicker', () => {
.withContext('focus should return to the picker input')
.toBeTrue();
expect(dateRange.isFocused).toBeTrue();

// reopen and close again
dateRange.open();
tick();
fixture.detectChanges();

calendarWrapper = document.getElementsByClassName('igx-calendar__wrapper')[0];
expect(calendarWrapper.contains(document.activeElement))
.withContext('focus should move to calendar for KB nav')
.toBeTrue();

UIInteractions.triggerKeyDownEvtUponElem('ArrowUp', calendarWrapper, true, true);
tick();
fixture.detectChanges();
expect(startInput.nativeElement.contains(document.activeElement))
.withContext('focus should return to the picker input')
.toBeTrue();
expect(dateRange.isFocused).toBeTrue();
}));

it('should not open calendar with ALT + DOWN ARROW key if disabled is set to true', fakeAsync(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,6 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
// input click
if (this.hasProjectedInputs && this._focusedInput) {
this._focusedInput.setFocus();
this._focusedInput = null;
}
if (this.inputDirective) {
this.inputDirective.focus();
Expand Down Expand Up @@ -813,6 +812,7 @@ export class IgxDateRangePickerComponent extends PickerBaseDirective
}

private updateValidityOnBlur() {
this._focusedInput = null;
this.onTouchCallback();
if (this._ngControl) {
if (this.hasProjectedInputs) {
Expand Down
Loading