Skip to content

Commit 6f029ba

Browse files
author
Kubit
committed
Include customBack prop text to Calendar component
1 parent 977c936 commit 6f029ba

File tree

6 files changed

+14
-13
lines changed

6 files changed

+14
-13
lines changed

src/components/calendar/calendarStandAlone.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { YearSelector } from './selector/yearSelector/yearSelector';
1212
import { ICalendarStandAlone } from './types';
1313

1414
const CalendarStandAloneComponent = (
15-
{ maxDate = new Date(), ...props }: ICalendarStandAlone,
15+
{ maxDate = new Date(), customBackText = 'Back', ...props }: ICalendarStandAlone,
1616
ref: React.ForwardedRef<HTMLDivElement> | undefined | null
1717
): React.JSX.Element => {
1818
const [showMonthSelector, setShowMonthSelector] = React.useState(false);
@@ -31,6 +31,7 @@ const CalendarStandAloneComponent = (
3131
configAccesibility={props.configAccesibility}
3232
configCalendar={props.configCalendar}
3333
currentDate={props.currentDate}
34+
customBackText={customBackText}
3435
maxDate={maxDate}
3536
minDate={props.minDate}
3637
setCurrentDate={props.setCurrentDate}

src/components/calendar/selector/__tests__/selector.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ describe('Selector component', () => {
3838
it('Selector with Range and selected Date Component', () => {
3939
renderProvider(<Selector {...mockProps} />);
4040

41-
const selector = screen.getByRole('button', {
42-
name: mockProps.configCalendar.leftArrowIcon['aria-label'],
43-
});
41+
const selector = screen.getByLabelText(mockProps.configCalendar.leftArrowIcon['aria-label']);
4442

4543
expect(selector).toBeInTheDocument();
4644
});

src/components/calendar/selector/selector.styled.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export const RightIconStyled = styled.span<RightIconType>`
3030
visibility: ${({ showCustomSelector }) => (showCustomSelector ? 'hidden' : 'visible')};
3131
`;
3232

33-
export const IconAndBackTextStyled = styled.div<SelectorStyledType>`
33+
export const IconAndBackTextStyled = styled.button<SelectorStyledType>`
3434
display: flex;
3535
flex-direction: row;
3636
align-items: center;
37+
cursor: pointer;
3738
${({ styles }) => getStyles(styles?.selectorIconAndBackTextContainer)};
3839
`;

src/components/calendar/selector/selector.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,22 +123,21 @@ export const Selector = (props: ISelector): JSX.Element => {
123123

124124
return (
125125
<SelectorStyled isDaySelector={isDaySelector} styles={props.styles}>
126-
<IconAndBackTextStyled styles={props.styles}>
126+
<IconAndBackTextStyled
127+
aria-label={showCustomSelector ? '' : leftArrowIcon['aria-label']}
128+
styles={props.styles}
129+
type="button"
130+
onClick={handleOnClickLeftIcon}
131+
>
127132
<ElementOrIcon
128133
color={iconArrowDisabled(props.minDate) ? props.styles?.colorArrowDisabled : undefined}
129134
customIconStyles={props.styles?.leftArrow}
130135
disabled={iconArrowDisabled(props.minDate)}
131136
{...leftArrowIcon}
132-
aria-label={
133-
showCustomSelector
134-
? props.configAccesibility?.backToMonthAriaLabel
135-
: leftArrowIcon['aria-label']
136-
}
137-
onClick={handleOnClickLeftIcon}
138137
/>
139138
{showCustomSelector && (
140139
<Text component={TextComponentType.PARAGRAPH} customTypography={props.styles?.backText}>
141-
{'Back'}
140+
{props.customBackText}
142141
</Text>
143142
)}
144143
</IconAndBackTextStyled>

src/components/calendar/selector/types/selector.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CalendarContainerStylesType } from '../../types/calendarTheme';
44

55
export interface ISelector {
66
currentDate: Date;
7+
customBackText?: string;
78
setCurrentDate: (date: Date) => void;
89
maxDate: Date;
910
minDate: Date;

src/components/calendar/types/calendar.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type IConfigAccesibility = {
3434
};
3535
export interface ICalendarStandAlone<V = undefined extends string ? unknown : string> {
3636
id?: string;
37+
customBackText?: string;
3738
selectedDate: Date[];
3839
hasRange?: boolean;
3940
disabledDates?: Date[];

0 commit comments

Comments
 (0)