Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(calendar): rtl navigation #4565

Open
wants to merge 3 commits into
base: canary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-deers-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/calendar": patch
---

Fixed reversed navigation behavior of nextButton and prevButton in the RTL calendar. The buttons now correctly navigate to the next and previous months, ensuring consistent behavior across all locales and layouts. (#4541)
23 changes: 19 additions & 4 deletions packages/components/calendar/src/calendar-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {VisuallyHidden} from "@react-aria/visually-hidden";
import {Button} from "@heroui/button";
import {chain, mergeProps} from "@react-aria/utils";
import {AnimatePresence, LazyMotion, MotionConfig} from "framer-motion";
import {useLocale} from "@react-aria/i18n";
import {ResizablePanel} from "@heroui/framer-utils";

import {ChevronLeftIcon} from "./chevron-left";
Expand Down Expand Up @@ -55,20 +56,29 @@ export function CalendarBase(props: CalendarBaseProps) {

const [direction, setDirection] = useState<number>(0);

const {direction: localeDirection} = useLocale();

const currentMonth = state.visibleRange.start;

const headers: React.ReactNode[] = [];
const calendars: React.ReactNode[] = [];

const isLTR = localeDirection === "ltr";

for (let i = 0; i < visibleMonths; i++) {
let d = currentMonth.add({months: i});

headers.push(
<Fragment key={`calendar-header-${i}`}>
{i === 0 && (
<Button
{...prevButtonProps}
onPress={chain(prevButtonProps.onPress, () => setDirection(-1))}
{...(isLTR ? prevButtonProps : nextButtonProps)}
className={
isLTR ? prevButtonProps?.["className"] : `${nextButtonProps?.["className"]} order-1`
}
onPress={chain(isLTR ? prevButtonProps.onPress : nextButtonProps.onPress, () =>
setDirection(-1),
)}
>
<ChevronLeftIcon />
</Button>
Expand All @@ -81,8 +91,13 @@ export function CalendarBase(props: CalendarBaseProps) {
/>
{i === visibleMonths - 1 && (
<Button
{...nextButtonProps}
onPress={chain(nextButtonProps.onPress, () => setDirection(1))}
{...(isLTR ? nextButtonProps : prevButtonProps)}
className={
isLTR ? nextButtonProps?.["className"] : `${prevButtonProps?.["className"]} order-3`
}
onPress={chain(isLTR ? nextButtonProps.onPress : prevButtonProps.onPress, () =>
setDirection(1),
)}
>
<ChevronRightIcon />
</Button>
Expand Down