Skip to content

Commit

Permalink
NEXT-38027 - fix datepicker not emiting value when manually entered
Browse files Browse the repository at this point in the history
  • Loading branch information
tajespasarela authored and Haberkamp committed Sep 11, 2024
1 parent a6df694 commit 307439b
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-numbers-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopware-ag/meteor-component-library": patch
---

Updated flatpickr dependency to the latest version to fix mt-datepicker issue when date typed manually
2 changes: 1 addition & 1 deletion packages/component-library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@vueuse/core": "^10.7.2",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
"flatpickr": "4.6.3",
"flatpickr": "4.6.13",
"focus-trap": "^7.5.4",
"inter-ui": "^3.19.3",
"lodash-es": "^4.17.21",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export const VisualTestTimeInputValue: MtDatepickerStory = {
// Enter 22 as minute
await userEvent.clear(calendar.getByLabelText("Minute"));
await userEvent.type(calendar.getByLabelText("Minute"), "22");
await userEvent.type(canvas.getByRole("textbox"), "{enter}");

// Click label to close datepicker
await userEvent.click(canvas.getByText(args.label!));
Expand Down Expand Up @@ -168,3 +169,34 @@ export const TestDisabledDoesNotOpenFlatpickr: MtDatepickerStory = {
expect((canvas.getByRole("textbox") as HTMLInputElement).disabled).toBe(true);
},
};

export const TestManualInput: MtDatepickerStory = {
name: "Should emit date value when manually typed",
args: {
label: "Date value",
dateType: "date",
modelValue: null,
},
play: async ({ canvasElement, args }) => {
const canvas = within(canvasElement);
const input = canvas.getByRole("textbox");

// Focus input
await userEvent.click(input);

// Clear input
await userEvent.clear(input);

// Enter date manually
await userEvent.type(input, "2024-12-24");

// Click label to close datepicker
await userEvent.click(canvas.getByText(args.label!));

// Expect input value
expect((input as HTMLInputElement).value).toBe("2024-12-24");

// Expect input event is triggered
expect(args.updateModelValue).toHaveBeenCalledWith("2024-12-24T00:00:00");
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,8 @@ export default defineComponent({
this.isDatepickerOpen = true;
});
this.flatpickrInstance.config.onClose.push(() => {
this.flatpickrInstance.config.onClose.push((...args) => {
this.emitValue(args[1]);
this.isDatepickerOpen = false;
});
Expand Down
19 changes: 12 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 307439b

Please sign in to comment.