Skip to content

Commit

Permalink
fix(calendar): disable button picker in calendar if isDisabled is t…
Browse files Browse the repository at this point in the history
…rue (#3358)

* fix(calendar): disable button picker in calendar if `isDisabled` is true

* feat(changeset): add changeset

* feat(calendar): add test to cover showMonthAndYearPickers with isDisabled
  • Loading branch information
wingkwong committed Jul 6, 2024
1 parent 167e197 commit fd4b720
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/friendly-pumas-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/calendar": patch
---

disable button picker in calendar if `isDisabled` is true (#3357)
10 changes: 10 additions & 0 deletions packages/components/calendar/__tests__/calendar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ describe("Calendar", () => {
expect(onChange).not.toHaveBeenCalled();
});

it("should not open a month & year picker if isDisabled is true", () => {
const {container} = render(
<Calendar isDisabled showMonthAndYearPickers value={new CalendarDate(2024, 6, 29)} />,
);

const headerButtonPicker = container.querySelector("[data-slot='header']");

expect(headerButtonPicker).toHaveAttribute("disabled");
});

it("should not select a date on click if isReadOnly", () => {
let onChange = jest.fn();
let {getByLabelText, getByText} = render(
Expand Down
4 changes: 2 additions & 2 deletions packages/components/calendar/src/use-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {useCalendar as useAriaCalendar} from "@react-aria/calendar";
import {useCalendarState} from "@react-stately/calendar";
import {createCalendar} from "@internationalized/date";
import {clsx} from "@nextui-org/shared-utils";
import {chain} from "@react-aria/utils";
import {chain, mergeProps} from "@react-aria/utils";

import {ContextType, useCalendarBase, UseCalendarBaseProps} from "./use-calendar-base";
import {CalendarBaseProps} from "./calendar-base";
Expand Down Expand Up @@ -76,7 +76,7 @@ export function useCalendar<T extends DateValue>({
const baseStyles = clsx(classNames?.base, className);

const buttonPickerProps: ButtonProps = {
...buttonPickerPropsProp,
...mergeProps(buttonPickerPropsProp, {isDisabled: originalProps.isDisabled}),
onPress: chain(buttonPickerPropsProp?.onPress, () => setIsHeaderExpanded(!isHeaderExpanded)),
};

Expand Down

0 comments on commit fd4b720

Please sign in to comment.