diff --git a/apps/builder/src/features/blocks/inputs/date/date.spec.ts b/apps/builder/src/features/blocks/inputs/date/date.spec.ts index ad6d688ea..d24468d3b 100644 --- a/apps/builder/src/features/blocks/inputs/date/date.spec.ts +++ b/apps/builder/src/features/blocks/inputs/date/date.spec.ts @@ -60,4 +60,64 @@ test.describe("Date input block", () => { page.locator('text="01.01 11:00 to 01.02 09:00"'), ).toBeVisible(); }); + + test("min/max date validation should work", async ({ page }) => { + const typebotId = createId(); + await createTypebots([ + { + id: typebotId, + ...parseDefaultGroupWithBlock({ + type: InputBlockType.DATE, + }), + }, + ]); + + await page.goto(`/typebots/${typebotId}/edit`); + + await page.click("text=Test"); + + // Return to edit mode to set min/max dates + await page.click(`text=Pick a date`); + await page.getByLabel("Min:").fill("2023-01-01"); + await page.getByLabel("Max:").fill("2023-12-31"); + + await page.click("text=Restart"); + + // Browser native validation should prevent entering dates outside range + await expect(page.locator('[data-testid="from-date"]')).toHaveAttribute( + "min", + "2023-01-01", + ); + await expect(page.locator('[data-testid="from-date"]')).toHaveAttribute( + "max", + "2023-12-31", + ); + + // Test valid date within range + await page.locator('[data-testid="from-date"]').fill("2023-06-15"); + await page.getByLabel("Send").click(); + await expect(page.locator('text="15/06/2023"')).toBeVisible(); + }); + + test("keyboard navigation and form submission should work", async ({ + page, + }) => { + const typebotId = createId(); + await createTypebots([ + { + id: typebotId, + ...parseDefaultGroupWithBlock({ + type: InputBlockType.DATE, + }), + }, + ]); + + await page.goto(`/typebots/${typebotId}/edit`); + await page.click("text=Test"); + + // Fill the date and submit using Enter key + await page.locator('[data-testid="from-date"]').fill("2023-07-04"); + await page.locator('[data-testid="from-date"]').press("Enter"); + await expect(page.locator('text="04/07/2023"')).toBeVisible(); + }); }); diff --git a/packages/embeds/js/src/features/blocks/inputs/date/components/DateForm.tsx b/packages/embeds/js/src/features/blocks/inputs/date/components/DateForm.tsx index fa291cd2d..c673248c0 100644 --- a/packages/embeds/js/src/features/blocks/inputs/date/components/DateForm.tsx +++ b/packages/embeds/js/src/features/blocks/inputs/date/components/DateForm.tsx @@ -26,6 +26,13 @@ export const DateForm = (props: Props) => { }); }; + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === "Enter") { + e.preventDefault(); + submit(); + } + }; + return (