-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor time-picker to be more keyboard friendly & refactor test hel…
…pers This changes the time-picker to work more like the date-picker. The trigger is now a simple button, where the input is in the dropdown - similar to ember-power-select. This makes a lot of the focus handling much easier.
- Loading branch information
Francesco Novy
committed
Oct 25, 2018
1 parent
827eed2
commit e90518f
Showing
12 changed files
with
376 additions
and
432 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { click, triggerKeyEvent, fillIn, find } from '@ember/test-helpers'; | ||
import moment from 'moment'; | ||
import { assert } from '@ember/debug'; | ||
import parseTime from 'ember-date-components/utils/parse-time'; | ||
|
||
export async function selectTime(element, val) { | ||
if (typeof element === 'string') { | ||
element = find(element); | ||
} | ||
|
||
assert('selectTime is passed a DOM node or a matching selector string', !!element); | ||
|
||
let timePickerButton = element.hasAttribute('data-time-picker-toggle-button') | ||
? element | ||
: element.querySelector('[data-time-picker-toggle-button]'); | ||
|
||
let elementId = timePickerButton.getAttribute('data-time-picker-toggle-button'); | ||
|
||
await click(timePickerButton); | ||
|
||
if (moment.isMoment(val)) { | ||
val = val.format('HH:mm'); | ||
} | ||
|
||
let timeInput = find(`[data-time-picker-input-instance="${elementId}"]`); | ||
await fillIn(timeInput, val); | ||
await triggerKeyEvent(timeInput, 'keydown', 'Enter'); // Enter event | ||
} | ||
|
||
export function getSelectedTime(element) { | ||
if (typeof element === 'string') { | ||
element = find(element); | ||
} | ||
|
||
assert('getSelectedTime is passed a DOM node or a matching selector string', !!element); | ||
|
||
let timePickerButton = element.hasAttribute('data-time-picker-toggle-button') | ||
? element | ||
: element.querySelector('[data-time-picker-toggle-button]'); | ||
|
||
let timeValue = timePickerButton.getAttribute('data-time-picker-value'); | ||
return timeValue ? parseTime(timeValue) : null; | ||
} | ||
|
||
export default { | ||
selectTime, | ||
getSelectedTime | ||
}; |
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
Oops, something went wrong.