Skip to content

Commit

Permalink
Merge pull request #383 from MyPureCloud/feature/COMUI-2616_v2
Browse files Browse the repository at this point in the history
fix(date-picker): first keypress after focus should be treated as new input
  • Loading branch information
gavin-everett-genesys authored Mar 25, 2024
2 parents 2a94370 + d01a9de commit 0102aa0
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ export class GuxDatepicker {
@State()
active: boolean = false;

/**
* Tracks the amount of key presses when focusing on the input.
*/
@State()
pressedKeys: Array<string> = [];

@Watch('value')
watchValue() {
this.updateDate();
Expand Down Expand Up @@ -240,6 +246,7 @@ export class GuxDatepicker {
);
this.setIntervalRange(previousIntervalRange);
this.setCursorRange();
this.pressedKeys.length = 0;
break;
}
case 'ArrowRight': {
Expand All @@ -251,6 +258,7 @@ export class GuxDatepicker {
);
this.setIntervalRange(nextIntervalRange);
this.setCursorRange();
this.pressedKeys.length = 0;
break;
}
default:
Expand Down Expand Up @@ -312,6 +320,7 @@ export class GuxDatepicker {
@OnClickOutside({ triggerEvents: 'mousedown' })
onClickOutside() {
this.active = false;
this.pressedKeys.length = 0;
}

/********* Event Handlers **********/
Expand Down Expand Up @@ -362,6 +371,7 @@ export class GuxDatepicker {
}

updateIntervalValue(event: KeyboardEvent): void {
this.pressedKeys.push(event.key);
const inputNumber = parseInt(event.key, 10);

if (!isNaN(inputNumber)) {
Expand All @@ -377,7 +387,7 @@ export class GuxDatepicker {
) {
this.typeYearValue(currentSectionValue, event.key);
} else {
if (this.canSetDate(inputNumber)) {
if (this.canSetDate(inputNumber) && this.pressedKeys.length >= 2) {
this.updateSelection(
this.focusedField,
`${currentSectionValue[1]}${event.key}`
Expand Down Expand Up @@ -479,7 +489,7 @@ export class GuxDatepicker {
}
}

canSetDate(key: number) {
canSetDate(key: number): boolean {
const newValue = parseInt(
[
this.focusedField.value[this.intervalRange.selectionEnd - 1].toString(),
Expand Down

0 comments on commit 0102aa0

Please sign in to comment.