Skip to content

Commit d88cee8

Browse files
committed
fix: Add inline mode support to CalendarComponent component with appropriate accessibility props
1 parent db67a58 commit d88cee8

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/calendar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,7 @@ export default class Calendar extends Component<CalendarProps, CalendarState> {
11541154
})}
11551155
showTime={this.props.showTimeSelect || this.props.showTimeInput}
11561156
showTimeSelectOnly={this.props.showTimeSelectOnly}
1157+
inline={this.props.inline}
11571158
>
11581159
{this.renderAriaLiveRegion()}
11591160
{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 | undefined;
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: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,7 @@ describe("Calendar", () => {
26792679
});
26802680

26812681
describe("calendar container", () => {
2682-
it("should render Calendar with accessibility props", () => {
2682+
it("should render Calendar in popover mode with dialog accessibility props", () => {
26832683
const { container } = render(
26842684
<Calendar
26852685
dateFormat={dateFormat}
@@ -2696,6 +2696,23 @@ describe("Calendar", () => {
26962696
expect(dialog?.getAttribute("aria-label")).toBe("Choose Date");
26972697
});
26982698

2699+
it("should render Calendar in inline mode without dialog accessibility props", () => {
2700+
const { container } = render(
2701+
<Calendar
2702+
dateFormat={dateFormat}
2703+
onClickOutside={() => {}}
2704+
onSelect={() => {}}
2705+
dropdownMode="scroll"
2706+
/>,
2707+
);
2708+
2709+
const dialog = container.querySelector(".react-datepicker");
2710+
expect(dialog).not.toBeNull();
2711+
expect(dialog).not.toHaveProperty("role");
2712+
expect(dialog).not.toHaveProperty("aria-modal");
2713+
expect(dialog?.getAttribute("aria-label")).toBe("Choose Date");
2714+
});
2715+
26992716
it("should display corresponding aria-label for Calendar with showTimeSelect", () => {
27002717
const { container } = render(
27012718
<Calendar

0 commit comments

Comments
 (0)