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 6 commits into
base: canary
Choose a base branch
from
Open
Changes from 1 commit
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
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 @@ -9,6 +9,7 @@ import {Button} from "@nextui-org/button";
import {chain, mergeProps} from "@react-aria/utils";
import {AnimatePresence, LazyMotion, MotionConfig} from "framer-motion";
import {ResizablePanel} from "@nextui-org/framer-utils";
import {useLocale} from "@react-aria/i18n";

import {ChevronLeftIcon} from "./chevron-left";
import {ChevronRightIcon} from "./chevron-right";
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";
MarufSharifi marked this conversation as resolved.
Show resolved Hide resolved

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`
}
MarufSharifi marked this conversation as resolved.
Show resolved Hide resolved
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),
)}
MarufSharifi marked this conversation as resolved.
Show resolved Hide resolved
>
<ChevronRightIcon />
</Button>
Expand Down
Loading