Skip to content

Commit

Permalink
feat: remove startMonth and endMonth default constraints when `dr…
Browse files Browse the repository at this point in the history
…opdown-months` is set as caption layout (#2648)

* examples: add DropdownMonths

* refactor: getYearOptions test

* feat: remove default startMonth and endMonth for dropdown-months

Remove default values when captionLayout equal to dropdown-months.

* refactor: Dropdown.test.tsx

* chore(test): add DropdownMonths.test.tsx

---------

Co-authored-by: Giampaolo Bellavite <[email protected]>
  • Loading branch information
rodgobbi and gpbl authored Dec 29, 2024
1 parent 1026b2c commit bcd5215
Show file tree
Hide file tree
Showing 9 changed files with 407 additions and 184 deletions.
5 changes: 0 additions & 5 deletions examples/Dropdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import { user } from "@/test/user";

import { Dropdown } from "./Dropdown";

const today = new Date(2015, 6, 1);

beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<Dropdown />);
});
Expand Down
26 changes: 26 additions & 0 deletions examples/DropdownMonths.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";

import { grid, monthDropdown, nextButton } from "@/test/elements";
import { render } from "@/test/render";
import { user } from "@/test/user";

import { DropdownMonths } from "./DropdownMonths";

const today = new Date(2015, 6, 1);

beforeAll(() => jest.setSystemTime(today));
afterAll(() => jest.useRealTimers());

beforeEach(() => {
render(<DropdownMonths />);
});

test("should display the month dropdown", () => {
expect(monthDropdown()).toBeInTheDocument();
});

test("should allow all months", async () => {
expect(grid()).toHaveAccessibleName(`December 2015`);
await user.click(nextButton());
expect(grid()).toHaveAccessibleName(`January 2016`);
});
12 changes: 12 additions & 0 deletions examples/DropdownMonths.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

import { DayPicker } from "react-day-picker";

export function DropdownMonths() {
const decemberDate = new Date();
decemberDate.setMonth(11);

return (
<DayPicker defaultMonth={decemberDate} captionLayout="dropdown-months" />
);
}
1 change: 1 addition & 0 deletions examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export * from "./Dialog";
export * from "./Disabled";
export * from "./DisableNavigation";
export * from "./Dropdown";
export * from "./DropdownMonths";
export * from "./DropdownMultipleMonths";
export * from "./Fixedweeks";
export * from "./FocusRecursive";
Expand Down
Loading

0 comments on commit bcd5215

Please sign in to comment.