Skip to content

Commit fec3673

Browse files
Merge pull request #6008 from ilchenkoArtem/fix-inline-container-attrs
fix: Add inline mode support to `CalendarComponent` component with correct accessibility attrs
2 parents 3c79e39 + d723856 commit fec3673

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/calendar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
11691169
})}
11701170
showTime={this.props.showTimeSelect || this.props.showTimeInput}
11711171
showTimeSelectOnly={this.props.showTimeSelectOnly}
1172+
inline={this.props.inline}
11721173
>
11731174
{this.renderAriaLiveRegion()}
11741175
{this.renderPreviousButton()}

src/calendar_container.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ export interface CalendarContainerProps
44
extends React.PropsWithChildren<HTMLAttributes<HTMLDivElement>> {
55
showTimeSelectOnly?: boolean;
66
showTime?: boolean;
7+
inline?: boolean;
78
}
89

910
const CalendarContainer: React.FC<CalendarContainerProps> = function ({
1011
showTimeSelectOnly = false,
1112
showTime = false,
1213
className,
1314
children,
15+
inline,
1416
}: CalendarContainerProps) {
1517
const ariaLabel = showTimeSelectOnly
1618
? "Choose Time"
@@ -19,9 +21,9 @@ const CalendarContainer: React.FC<CalendarContainerProps> = function ({
1921
return (
2022
<div
2123
className={className}
22-
role="dialog"
2324
aria-label={ariaLabel}
24-
aria-modal="true"
25+
role={inline ? undefined : "dialog"}
26+
aria-modal={inline ? undefined : "true"}
2527
>
2628
{children}
2729
</div>

src/test/calendar_test.test.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2731,7 +2731,7 @@ describe("Calendar", () => {
27312731
});
27322732

27332733
describe("calendar container", () => {
2734-
it("should render Calendar with accessibility props", () => {
2734+
it("should render Calendar in popover mode with dialog accessibility props", () => {
27352735
const { container } = render(
27362736
<Calendar
27372737
dateFormat={dateFormat}
@@ -2748,6 +2748,24 @@ describe("Calendar", () => {
27482748
expect(dialog?.getAttribute("aria-label")).toBe("Choose Date");
27492749
});
27502750

2751+
it("should render Calendar in inline mode without dialog accessibility props", () => {
2752+
const { container } = render(
2753+
<Calendar
2754+
dateFormat={dateFormat}
2755+
onClickOutside={() => {}}
2756+
onSelect={() => {}}
2757+
dropdownMode="scroll"
2758+
inline
2759+
/>,
2760+
);
2761+
2762+
const dialog = container.querySelector(".react-datepicker");
2763+
expect(dialog).not.toBeNull();
2764+
expect(dialog?.getAttribute("role")).toBeNull();
2765+
expect(dialog?.getAttribute("aria-modal")).toBeNull();
2766+
expect(dialog?.getAttribute("aria-label")).toBe("Choose Date");
2767+
});
2768+
27512769
it("should display corresponding aria-label for Calendar with showTimeSelect", () => {
27522770
const { container } = render(
27532771
<Calendar

0 commit comments

Comments
 (0)