-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(timepicker): fix tab navigation & handling keyboard arrows (#2053)
FIxes #1836
- Loading branch information
1 parent
6c72421
commit 7efa35c
Showing
9 changed files
with
167 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
e2e-app/src/app/timepicker/navigation/timepicker-navigation.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<input id="before" /> | ||
|
||
<ngb-timepicker | ||
[seconds]="true" | ||
[(ngModel)]="time" | ||
></ngb-timepicker> | ||
|
||
<input id="after" /> |
8 changes: 8 additions & 0 deletions
8
e2e-app/src/app/timepicker/navigation/timepicker-navigation.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import {Component} from '@angular/core'; | ||
|
||
@Component({ | ||
templateUrl: './timepicker-navigation.component.html', | ||
}) | ||
export class TimepickerNavigationComponent { | ||
time = {hour: 13, minute: 30, second: 30}; | ||
} |
77 changes: 77 additions & 0 deletions
77
e2e-app/src/app/timepicker/navigation/timepicker-navigation.e2e-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import {Key, ElementFinder} from 'protractor'; | ||
|
||
import {openUrl, expectFocused, sendKey, getCaretPosition} from '../../tools.po'; | ||
|
||
import {TimepickerNavigationPage} from './timepicker-navigation.po'; | ||
|
||
describe('Timepicker', () => { | ||
let page: TimepickerNavigationPage; | ||
|
||
beforeAll(() => page = new TimepickerNavigationPage()); | ||
beforeEach(async() => await openUrl('timepicker/navigation')); | ||
|
||
async function expectCaretPosition(field: ElementFinder, position: number) { | ||
const {start, end} = await getCaretPosition(field); | ||
expect(end).toBe(end, 'Caret should be at single position (no range selected)'); | ||
expect(start).toBe(position, `Caret is not at proper position for given field`); | ||
} | ||
|
||
describe('navigation', () => { | ||
it(`should jump between inputs`, async() => { | ||
await page.focusInputBefore(); | ||
|
||
const[hourField, minuteField, secondField] = page.getFields(); | ||
|
||
await sendKey(Key.TAB); | ||
await expectFocused(hourField, 'Hour field should be focused'); | ||
await sendKey(Key.TAB); | ||
await expectFocused(minuteField, 'Minute field should be focused'); | ||
await sendKey(Key.TAB); | ||
await expectFocused(secondField, 'Second field should be focused'); | ||
await sendKey(Key.TAB); | ||
await expectFocused(page.getInputAfter(), 'Input after should be focused'); | ||
|
||
await sendKey(Key.SHIFT, Key.TAB); | ||
await expectFocused(secondField, 'Second field should be focused'); | ||
await sendKey(Key.SHIFT, Key.TAB); | ||
await expectFocused(minuteField, 'Minute field should be focused'); | ||
await sendKey(Key.SHIFT, Key.TAB); | ||
await expectFocused(hourField, 'Hour field should be focused'); | ||
await sendKey(Key.SHIFT, Key.TAB); | ||
await expectFocused(page.getInputBefore(), 'Input before should be focused'); | ||
}); | ||
}); | ||
|
||
describe('arrow keys', () => { | ||
it(`should keep caret at the end of the input`, async() => { | ||
const testField = async(fieldElement: ElementFinder) => { | ||
await fieldElement.click(); | ||
|
||
const endPosition = 2; | ||
const expectCaretAtEnd = () => expectCaretPosition(fieldElement, endPosition); | ||
|
||
await sendKey(Key.END); | ||
await expectCaretAtEnd(); | ||
|
||
await sendKey(Key.ARROW_UP); | ||
await expectCaretAtEnd(); | ||
|
||
await sendKey(Key.ARROW_DOWN); | ||
await expectCaretAtEnd(); | ||
|
||
await sendKey(Key.HOME); | ||
await expectCaretPosition(fieldElement, 0); | ||
|
||
await sendKey(Key.ARROW_UP); | ||
await expectCaretAtEnd(); | ||
|
||
await sendKey(Key.ARROW_DOWN); | ||
await expectCaretAtEnd(); | ||
}; | ||
|
||
for (const fieldElement of page.getFields()) { | ||
await testField(fieldElement); | ||
} | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
e2e-app/src/app/timepicker/navigation/timepicker-navigation.po.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {$} from 'protractor'; | ||
|
||
export type Field = 'hour' | 'minute' | 'second'; | ||
|
||
export class TimepickerNavigationPage { | ||
getInputBefore() { return $('#before'); } | ||
focusInputBefore() { return this.getInputBefore().click(); } | ||
|
||
getInputAfter() { return $('#after'); } | ||
getField(field: Field) { return $(`.ngb-tp-${field} > input`); } | ||
|
||
getFields() { return ['hour', 'minute', 'second'].map((field: Field) => this.getField(field)); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters