Skip to content

Commit 761cecf

Browse files
authored
chore(DatePicker): Address Left/Right arrows in calendar for RTL (#3335)
address left/right buttons in calendar for RTL
1 parent 21a4a04 commit 761cecf

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

packages/gamut/src/DatePicker/DatePickerCalendar/Calendar/CalendarNavLastMonth.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { MiniChevronLeftIcon } from '@codecademy/gamut-icons';
1+
import {
2+
MiniChevronLeftIcon,
3+
MiniChevronRightIcon,
4+
} from '@codecademy/gamut-icons';
5+
import { useElementDir } from '@codecademy/gamut-styles';
26
import * as React from 'react';
37

48
import { IconButton } from '../../../Button';
@@ -17,6 +21,7 @@ export const CalendarNavLastMonth: React.FC<CalendarNavProps> = ({
1721
const resolvedLocale = useResolvedLocale(locale);
1822
const { lastMonth } = getRelativeMonthLabels(resolvedLocale);
1923
const buttonRef = React.useRef<HTMLButtonElement>(null);
24+
const isRtl = useElementDir(buttonRef) === 'rtl';
2025

2126
const handleClick = (e: React.MouseEvent) => {
2227
const lastMonth = new Date(
@@ -43,7 +48,7 @@ export const CalendarNavLastMonth: React.FC<CalendarNavProps> = ({
4348
alignSelf="flex-start"
4449
aria-label={lastMonth}
4550
data-calendar-month-nav
46-
icon={MiniChevronLeftIcon}
51+
icon={isRtl ? MiniChevronRightIcon : MiniChevronLeftIcon}
4752
ref={buttonRef}
4853
size="small"
4954
tip={lastMonth}

packages/gamut/src/DatePicker/DatePickerCalendar/Calendar/CalendarNavNextMonth.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { MiniChevronRightIcon } from '@codecademy/gamut-icons';
1+
import {
2+
MiniChevronLeftIcon,
3+
MiniChevronRightIcon,
4+
} from '@codecademy/gamut-icons';
5+
import { useElementDir } from '@codecademy/gamut-styles';
26
import * as React from 'react';
37

48
import { IconButton } from '../../../Button';
@@ -17,6 +21,7 @@ export const CalendarNavNextMonth: React.FC<CalendarNavProps> = ({
1721
const resolvedLocale = useResolvedLocale(locale);
1822
const { nextMonth } = getRelativeMonthLabels(resolvedLocale);
1923
const buttonRef = React.useRef<HTMLButtonElement>(null);
24+
const isRtl = useElementDir(buttonRef) === 'rtl';
2025

2126
const handleClick = (e: React.MouseEvent) => {
2227
const nextMonth = new Date(
@@ -43,7 +48,7 @@ export const CalendarNavNextMonth: React.FC<CalendarNavProps> = ({
4348
alignSelf="flex-end"
4449
aria-label={nextMonth}
4550
data-calendar-month-nav
46-
icon={MiniChevronRightIcon}
51+
icon={isRtl ? MiniChevronLeftIcon : MiniChevronRightIcon}
4752
ref={buttonRef}
4853
size="small"
4954
tip={nextMonth}

0 commit comments

Comments
 (0)