Skip to content

Commit 773dc52

Browse files
committed
feat(drp): handle the alt + arrow down/up focus properly for single input; add test for both input modes
1 parent 8870280 commit 773dc52

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

src/components/date-range-picker/date-range-picker-single.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { spy } from 'sinon';
99
import IgcCalendarComponent from '../calendar/calendar.js';
1010
import { CalendarDay } from '../calendar/model.js';
1111
import {
12+
altKey,
13+
arrowDown,
1214
arrowLeft,
1315
arrowRight,
1416
arrowUp,
@@ -820,6 +822,31 @@ describe('Date range picker - single input', () => {
820822
await elementUpdated(picker);
821823
expect(input.value).to.equal('01/01/2000 - 04/23/2025');
822824
});
825+
826+
it('should toggle the calendar dropdown with alt + arrow down/up and keep it focused', async () => {
827+
const eventSpy = spy(picker, 'emitEvent');
828+
input = getInput(picker);
829+
input.focus();
830+
831+
expect(isFocused(input)).to.be.true;
832+
833+
simulateKeyboard(input, [altKey, arrowDown]);
834+
await elementUpdated(picker);
835+
836+
expect(picker.open).to.be.true;
837+
expect(isFocused(input)).to.be.false;
838+
expect(eventSpy.firstCall).calledWith('igcOpening');
839+
expect(eventSpy.lastCall).calledWith('igcOpened');
840+
eventSpy.resetHistory();
841+
842+
simulateKeyboard(input, [altKey, arrowUp]);
843+
await elementUpdated(picker);
844+
845+
expect(picker.open).to.be.false;
846+
expect(isFocused(input)).to.be.true;
847+
expect(eventSpy.firstCall).calledWith('igcClosing');
848+
expect(eventSpy.lastCall).calledWith('igcClosed');
849+
});
823850
});
824851

825852
describe('Readonly state', () => {

src/components/date-range-picker/date-range-picker-two-inputs.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { spy } from 'sinon';
99
import IgcCalendarComponent from '../calendar/calendar.js';
1010
import { CalendarDay } from '../calendar/model.js';
1111
import {
12+
altKey,
1213
arrowDown,
1314
arrowUp,
1415
escapeKey,
@@ -802,6 +803,29 @@ describe('Date range picker - two inputs', () => {
802803

803804
checkDatesEqual(calendar.activeDate, june3rd2025);
804805
});
806+
it('should toggle the calendar dropdown with alt + arrow down/up and keep it focused', async () => {
807+
const eventSpy = spy(picker, 'emitEvent');
808+
dateTimeInputs[0].focus();
809+
810+
expect(isFocused(dateTimeInputs[0])).to.be.true;
811+
812+
simulateKeyboard(dateTimeInputs[0], [altKey, arrowDown]);
813+
await elementUpdated(picker);
814+
815+
expect(picker.open).to.be.true;
816+
expect(isFocused(dateTimeInputs[0])).to.be.false;
817+
expect(eventSpy.firstCall).calledWith('igcOpening');
818+
expect(eventSpy.lastCall).calledWith('igcOpened');
819+
eventSpy.resetHistory();
820+
821+
simulateKeyboard(dateTimeInputs[0], [altKey, arrowUp]);
822+
await elementUpdated(picker);
823+
824+
expect(picker.open).to.be.false;
825+
expect(isFocused(dateTimeInputs[0])).to.be.true;
826+
expect(eventSpy.firstCall).calledWith('igcClosing');
827+
expect(eventSpy.lastCall).calledWith('igcClosed');
828+
});
805829
});
806830
describe('Readonly state', () => {
807831
beforeEach(async () => {

src/components/date-range-picker/date-range-picker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ export default class IgcDateRangePickerComponent extends FormAssociatedRequiredM
782782
if (!this._isDropDown) {
783783
this._revertValue();
784784
}
785-
this._inputs[0]?.focus();
785+
this.useTwoInputs ? this._inputs[0].focus() : this._input.focus();
786786
}
787787
}
788788

0 commit comments

Comments
 (0)