Skip to content

Commit

Permalink
fix: missing aria labels in date range picker (#2832)
Browse files Browse the repository at this point in the history
* fix(date-range-picker): ensure label props are reflected in aria labels

* docs: added missing label to date range picker

* chore: add changesets

* Update .changeset/gentle-pigs-admire.md

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
  • Loading branch information
ryo-manba and coderabbitai[bot] authored Apr 22, 2024
1 parent 10b0e47 commit 1cc5215
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-pigs-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nextui-org/date-picker": patch
---

Fixed missing aria labels in date range picker (#2804)
8 changes: 5 additions & 3 deletions apps/docs/content/components/date-range-picker/time-zones.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const AppTs = `import {DateRangePicker} from "@nextui-org/react";
const App = `import {DateRangePicker} from "@nextui-org/react";
import {parseZonedDateTime, parseAbsoluteToLocal} from "@internationalized/date";
export default function App() {
Expand All @@ -9,21 +9,23 @@ export default function App() {
start: parseZonedDateTime("2024-04-01T00:45[America/Los_Angeles]"),
end: parseZonedDateTime("2024-04-14T11:15[America/Los_Angeles]"),
}}
label="Stay duration"
labelPlacement="outside"
/>
<DateRangePicker
defaultValue={{
start: parseAbsoluteToLocal("2024-04-01T07:45:00Z"),
end: parseAbsoluteToLocal("2024-04-14T19:15:00Z"),
}}
label="Stay duration"
labelPlacement="outside"
/>
</div>
</div>
);
}`;

const react = {
"/App.tsx": AppTs,
"/App.jsx": App,
};

export default {
Expand Down
14 changes: 7 additions & 7 deletions packages/components/date-picker/src/use-date-range-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export type UseDateRangePickerProps<T extends DateValue> = Props<T> & AriaDateRa

export function useDateRangePicker<T extends DateValue>({
as,
label,
isInvalid,
description,
startContent,
Expand Down Expand Up @@ -96,8 +95,6 @@ export function useDateRangePicker<T extends DateValue>({

const popoverTriggerRef = useRef<HTMLDivElement>(null);

originalProps.minValue;

let {
groupProps,
labelProps,
Expand Down Expand Up @@ -131,12 +128,15 @@ export function useDateRangePicker<T extends DateValue>({
const showTimeField = !!timeGranularity;

const labelPlacement = useMemo<DateInputVariantProps["labelPlacement"]>(() => {
if ((!originalProps.labelPlacement || originalProps.labelPlacement === "inside") && !label) {
if (
(!originalProps.labelPlacement || originalProps.labelPlacement === "inside") &&
!originalProps.label
) {
return "outside";
}

return originalProps.labelPlacement ?? "inside";
}, [originalProps.labelPlacement, label]);
}, [originalProps.labelPlacement, originalProps.label]);

const shouldLabelBeOutside = labelPlacement === "outside" || labelPlacement === "outside-left";

Expand Down Expand Up @@ -371,7 +371,7 @@ export function useDateRangePicker<T extends DateValue>({
const getDateInputGroupProps = () => {
return {
as,
label,
label: originalProps.label,
description,
endContent,
errorMessage,
Expand Down Expand Up @@ -400,7 +400,7 @@ export function useDateRangePicker<T extends DateValue>({

return {
state,
label,
label: originalProps.label,
slots,
classNames,
endContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ const TimeZonesTemplate = (args: DateRangePickerProps) => (
/>
<DateRangePicker
// {...args}
aria-label="Event date"
className="max-w-xs"
defaultValue={{
start: parseAbsoluteToLocal("2024-04-01T07:45:00Z"),
Expand Down

0 comments on commit 1cc5215

Please sign in to comment.