Normalize countdown keyboard adjustments and roll seconds across minutes
Co-authored-by: Shelley <shelley@exe.dev>
This commit is contained in:
parent
9c993beda8
commit
ebfd6e4ce1
3 changed files with 48 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { Countdown, integer } from './timer.mjs';
|
||||
import { Countdown, integer, adjustTime } from './timer.mjs';
|
||||
|
||||
const timer = new Countdown();
|
||||
const minutes = document.querySelector('#minutes');
|
||||
|
|
@ -55,8 +55,10 @@ for (const field of fields) {
|
|||
if (field.readOnly || !['ArrowUp', 'ArrowDown'].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
const step = event.shiftKey ? 10n : 1n;
|
||||
const value = integer(field.value) + (event.key === 'ArrowUp' ? step : -step);
|
||||
field.value = String(value < 0n ? 0n : value);
|
||||
const adjusted = adjustTime(minutes.value, seconds.value, field.id,
|
||||
event.key === 'ArrowUp' ? step : -step);
|
||||
minutes.value = adjusted.minutes;
|
||||
seconds.value = adjusted.seconds;
|
||||
edited();
|
||||
});
|
||||
field.addEventListener('blur', () => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue