adobe / adobe/react-spectrum

Cannot Access isInvalid Prop from DateRangePicker onChange Handler

Open
#8,228 9 comments 0 reactions 0 assignees View on GitHub
DatePicker enhancement help wanted
Dominant language
TypeScript
Stars
15.9k
Forks
1.6k
Avg merge
3d 9m
Merged PRs (30d)
59

Description

### Provide a general summary of the issue here

I'm trying to validate a date range selection using the `isInvalid` prop inside the `onChange` callback of the `DateRangePicker`. However, `isInvalid` does not seem to be accessible there. I need to conditionally run logic based on whether the selection is valid.

Is there a correct way to do this behaviour? I must not be the first one to want to check for validity before using the value in the onChange.

### 🤔 Expected Behavior?

`isInvalid` should be available inside the `onChange` handler or via another mechanism during date selection.

### 😯 Current Behavior

Can only access the `isInvalid ` prop from children of the `DateRangePicker` element.

### 💁 Possible Solution

_No response_

### 🔦 Context

_No response_

### 🖥️ Steps to Reproduce

```
import { parseDate } from "@internationalized/date"
import { CalendarIcon } from "lucide-react"

import { Button } from "@/registry/default/ui/button"
import {
CalendarCell,
CalendarGrid,
CalendarGridBody,
CalendarGridHeader,
CalendarHeaderCell,
CalendarHeading,
RangeCalendar,
} from "@/registry/default/ui/calendar"
import {
DatePickerContent,
DateRangePicker,
} from "@/registry/default/ui/date-picker"
import { DateInput } from "@/registry/default/ui/datefield"
import { FieldGroup, Label } from "@/registry/default/ui/field"

export default function DateRangePickerDemo() {
return (
{
console.log("Check validity here")
}}
maxValue={parseDate("2023-10-01")} //Should trigger validation
>
{(props) => {
console.log("isInvalid", props.isInvalid)
return (
<>
Date range



-










{(day) => {day}}


{(date) => }





)
}}

)
}
```

### Version

"react-aria-components": "^1.6.0",

### What browsers are you seeing the problem on?

Chrome

### If other, please specify.

_No response_

### What operating system are you using?

Windows

### 🧢 Your Company/Team

_No response_

### 🕷 Tracking Issue

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.