Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export enum Weekday {
Saturday
}

export interface InlineCalendarProps {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe call it CalendarMonthInlineProps

/** Component wrapping the calendar month when used inline. Recommended to be 'article'. */
wrapperComponent?: keyof JSX.IntrinsicElements;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just call this component?

/** Title of the calendar rendered above the inline calendar month. Recommended to be a 'title' component. */
title?: React.ReactNode;
/** Id of the accessible label of the calendar month. Recommended to map to the title. */
ariaLabeledby?: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just missing a lowercase l (though curiously the attribute still works in Chrome):

Suggested change
ariaLabeledby?: string;
ariaLabelledby?: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thatblindgeye If the consumer actually passes InProps. should we require the ariaLabelledby prop?

Copy link
Copy Markdown
Contributor

@thatblindgeye thatblindgeye Dec 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside to making it required is that if the wrapperComponent inlineProp is passed "div", the ARIA labeling attributes aren't well supported, so aria-labelledby shouldn't be passed in in that case.

}

/** Additional properties that extend from and can be passed to the main component. These
* properties allow customizing the calendar formatting and aria-labels.
*/
Expand Down Expand Up @@ -49,6 +58,8 @@ export interface CalendarFormat {
weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | Weekday;
/** Accessible label for the year input. */
yearInputAriaLabel?: string;
/** */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a description here

inlineProps?: InlineCalendarProps;
}

export interface CalendarProps extends CalendarFormat, Omit<React.HTMLProps<HTMLDivElement>, 'onChange'> {
Expand Down Expand Up @@ -133,6 +144,7 @@ export const CalendarMonth = ({
yearInputAriaLabel = 'Select year',
cellAriaLabel,
isDateFocused = false,
inlineProps,
...props
}: CalendarProps) => {
const longMonths = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11].map(monthNum => new Date(1990, monthNum)).map(monthFormat);
Expand Down Expand Up @@ -232,7 +244,8 @@ export const CalendarMonth = ({
const isHoveredDateValid = isValidated(hoveredDate);
const monthFormatted = monthFormat(focusedDate);
const yearFormatted = yearFormat(focusedDate);
return (

const calendarToRender = (
<div className={css(styles.calendarMonth, className)} {...props}>
<div className={styles.calendarMonthHeader}>
<div className={css(styles.calendarMonthHeaderNavControl, styles.modifiers.prevMonth)}>
Expand Down Expand Up @@ -386,4 +399,16 @@ export const CalendarMonth = ({
</table>
</div>
);

if (inlineProps !== undefined) {
const Component = (inlineProps.wrapperComponent ? inlineProps.wrapperComponent : 'article') as any;
return (
<Component {...(inlineProps.ariaLabeledby && { 'aria-labeledby': inlineProps.ariaLabeledby })}>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Component {...(inlineProps.ariaLabeledby && { 'aria-labeledby': inlineProps.ariaLabeledby })}>
<Component {...(inlineProps.ariaLabelledby && { 'aria-labelledby': inlineProps.ariaLabelledby })}>

{inlineProps.title}
{calendarToRender}
</Component>
);
}
return calendarToRender;
};
CalendarMonth.displayName = 'CalendarMonth';
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,11 @@ test('Next year dates have correct year in aria label', () => {
const nextYearDate = screen.getByRole('button', { name: '1 January 2025' });
expect(nextYearDate).toBeVisible();
});

test('InlineProps render correct wrapper component and attributes', () => {
const { asFragment } = render(
<CalendarMonth inlineProps={{wrapperComponent: 'article', title: <div id="hi">Title</div>, ariaLabeledby: "hi"}} />
);

expect(asFragment()).toMatchSnapshot();
});
Loading