Skip to content

Commit fe8e4b8

Browse files
Merge remote-tracking branch 'origin/main' into fix/change-month-offset-reset
2 parents 63fcf4e + bd3ab11 commit fe8e4b8

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ export type DatePickerProps = OmitUnion<
192192
tabIndex?: number;
193193
ariaDescribedBy?: string;
194194
ariaInvalid?: string;
195+
ariaLabel?: string;
195196
ariaLabelledBy?: string;
196197
ariaRequired?: string;
197198
"aria-describedby"?: string;
198199
"aria-invalid"?: string;
200+
"aria-label"?: string;
199201
"aria-labelledby"?: string;
200202
"aria-required"?: string;
201203
rangeSeparator?: string;
@@ -1589,13 +1591,15 @@ export class DatePicker extends Component<DatePickerProps, DatePickerState> {
15891591
const ariaDescribedBy =
15901592
this.props["aria-describedby"] ?? this.props.ariaDescribedBy;
15911593
const ariaInvalid = this.props["aria-invalid"] ?? this.props.ariaInvalid;
1594+
const ariaLabel = this.props["aria-label"] ?? this.props.ariaLabel;
15921595
const ariaLabelledBy =
15931596
this.props["aria-labelledby"] ?? this.props.ariaLabelledBy;
15941597
const ariaRequired = this.props["aria-required"] ?? this.props.ariaRequired;
15951598

15961599
if (ariaDescribedBy != null)
15971600
ariaProps["aria-describedby"] = ariaDescribedBy;
15981601
if (ariaInvalid != null) ariaProps["aria-invalid"] = ariaInvalid;
1602+
if (ariaLabel != null) ariaProps["aria-label"] = ariaLabel;
15991603
if (ariaLabelledBy != null) ariaProps["aria-labelledby"] = ariaLabelledBy;
16001604
if (ariaRequired != null) ariaProps["aria-required"] = ariaRequired;
16011605

src/test/datepicker_test.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4403,20 +4403,50 @@ describe("DatePicker", () => {
44034403
expect(input.getAttribute("aria-required")).toBe("true");
44044404
});
44054405

4406+
it("should pass aria-label to the input using standard HTML attribute name", () => {
4407+
const { container } = render(
4408+
<DatePicker selected={newDate()} aria-label="Select a date" />,
4409+
);
4410+
const input = safeQuerySelector(container, "input");
4411+
expect(input.getAttribute("aria-label")).toBe("Select a date");
4412+
});
4413+
4414+
it("should pass aria-label to the input using camelCase prop name", () => {
4415+
const { container } = render(
4416+
<DatePicker selected={newDate()} ariaLabel="Select a date" />,
4417+
);
4418+
const input = safeQuerySelector(container, "input");
4419+
expect(input.getAttribute("aria-label")).toBe("Select a date");
4420+
});
4421+
4422+
it("should prefer standard HTML attribute name over camelCase for aria-label", () => {
4423+
const { container } = render(
4424+
<DatePicker
4425+
selected={newDate()}
4426+
aria-label="standard-label"
4427+
ariaLabel="camelcase-label"
4428+
/>,
4429+
);
4430+
const input = safeQuerySelector(container, "input");
4431+
expect(input.getAttribute("aria-label")).toBe("standard-label");
4432+
});
4433+
44064434
it("should pass aria attributes to custom input using standard HTML attribute names", () => {
44074435
const { container } = render(
44084436
<DatePicker
44094437
selected={newDate()}
44104438
customInput={<CustomInput />}
44114439
aria-describedby="desc-id"
44124440
aria-invalid="true"
4441+
aria-label="date-label"
44134442
aria-labelledby="label-id"
44144443
aria-required="true"
44154444
/>,
44164445
);
44174446
const input = safeQuerySelector(container, "input");
44184447
expect(input.getAttribute("aria-describedby")).toBe("desc-id");
44194448
expect(input.getAttribute("aria-invalid")).toBe("true");
4449+
expect(input.getAttribute("aria-label")).toBe("date-label");
44204450
expect(input.getAttribute("aria-labelledby")).toBe("label-id");
44214451
expect(input.getAttribute("aria-required")).toBe("true");
44224452
});

0 commit comments

Comments
 (0)