Skip to content

Commit

Permalink
fix: datepicker input.change
Browse files Browse the repository at this point in the history
  • Loading branch information
segunadebayo committed Jan 15, 2025
1 parent 107ae42 commit a3c629b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .xstate/date-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const fetchMachine = createMachine({
},
"INPUT.CHANGE": [{
cond: "isInputValueEmpty",
actions: ["clearDateValue"]
actions: ["setInputValue", "clearDateValue"]
}, {
actions: ["setInputValue", "focusParsedDate"]
}],
Expand Down
8 changes: 6 additions & 2 deletions packages/machines/date-picker/src/date-picker.machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function machine(userContext: UserDefinedContext) {
"INPUT.CHANGE": [
{
guard: "isInputValueEmpty",
actions: ["clearDateValue"],
actions: ["setInputValue", "clearDateValue"],
},
{
actions: ["setInputValue", "focusParsedDate"],
Expand Down Expand Up @@ -912,9 +912,13 @@ export function machine(userContext: UserDefinedContext) {

// reset to last valid date
if (!date || !isValidDate(date)) {
date = ctx.focusedValue.copy()
if (ctx.inputValue) {
date = ctx.focusedValue.copy()
}
}

if (!date) return

const values = Array.from(ctx.value)
values[evt.index] = date

Expand Down

0 comments on commit a3c629b

Please sign in to comment.