-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix(radio): emit form-friendly onChange on RadioGroup for RHF #5821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
228d1c2
d5a5b86
e126a87
2c5bb9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -362,6 +362,48 @@ You can customize the `DateRangePicker` component by passing custom Tailwind CSS | |
|
|
||
| <Spacer y={4} /> | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### Common Issues | ||
|
|
||
| #### onFocusChange only updates start date | ||
| When using `onFocusChange` in DateRangePicker, make sure to handle both start and end date focus changes properly: | ||
|
|
||
| ```jsx | ||
| // ❌ Wrong - only updates start date | ||
| onFocusChange: (val) => setValue({...value, start: val}), | ||
|
|
||
| // ✅ Correct - handles both start and end focus | ||
| onFocusChange: (val) => { | ||
| if (val === "start") { | ||
| setValue({...value, start: val}); | ||
| } else if (val === "end") { | ||
| setValue({...value, end: val}); | ||
| } | ||
| }, | ||
| ``` | ||
|
Comment on lines
+372
to
+384
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Documentation example has the same bug as the code. The "correct" example still contains the critical error identified in The documentation needs to be corrected to show the proper usage. Based on the actual -// ✅ Correct - handles both start and end focus
-onFocusChange: (val) => {
- if (val === "start") {
- setValue({...value, start: val});
- } else if (val === "end") {
- setValue({...value, end: val});
- }
-},
+// ✅ Correct - onFocusChange receives the focused date value
+onFocusChange: (focusedValue) => {
+ // focusedValue is the date that now has focus
+ // Typically you only need this for advanced use cases
+ // For basic range selection, this handler is often not needed
+},Alternatively, if the Troubleshooting section is addressing a different issue, please clarify what 🤖 Prompt for AI Agents |
||
|
|
||
| #### Missing React import | ||
| Make sure to import React when using DateRangePicker in your components: | ||
|
|
||
| ```jsx | ||
| import React from "react"; | ||
| import {DateRangePicker} from "@heroui/react"; | ||
| ``` | ||
|
|
||
| #### Date range not updating properly | ||
| Ensure you're using the correct value structure for date ranges: | ||
|
|
||
| ```jsx | ||
| // ✅ Correct structure | ||
| const [value, setValue] = useState({ | ||
| start: today(getLocalTimeZone()), | ||
| end: today(getLocalTimeZone()).add({days: 7}) | ||
| }); | ||
| ``` | ||
|
|
||
| <Spacer y={4} /> | ||
|
|
||
| ## API | ||
|
|
||
| ### DateRangePicker Props | ||
|
|
@@ -684,7 +726,7 @@ You can customize the `DateRangePicker` component by passing custom Tailwind CSS | |
| { | ||
| attribute: "onFocusChange", | ||
| type: "(isFocused: boolean) => void", | ||
| description: "Handler that is called when the element's focus status changes.", | ||
| description: "Handler that is called when the element's focus status changes. **Important**: When using this with DateRangePicker, make sure to handle both start and end date focus changes properly to avoid losing the end date selection.", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify the onFocusChange API behavior and update documentation accordingly. The updated description suggests handling "both start and end date focus changes" but may be based on incorrect assumptions about the Please verify the actual signature and behavior of Once verified, update the description to accurately reflect the API's actual behavior. 🏁 Script executed: #!/bin/bash
# Search for onFocusChange implementation in DateRangePicker
ast-grep --pattern $'onFocusChange: ($$$) => {
$$$
}'
# Find the type definition for onFocusChange
rg -nP --type=ts -C5 'onFocusChange.*:.*\(' Length of output: 2161 🏁 Script executed: #!/bin/bash
# Find DateRangePicker component
fd -e ts -e tsx 'date-range-picker' --type f | grep -E '(src|component)' | head -20
# Search for onFocusChange in date-picker package
rg -n 'onFocusChange' packages/components/date-picker/src/ -A2 -B2 --type ts --type tsxLength of output: 296 🏁 Script executed: #!/bin/bash
# Inspect DateRangePicker component
cat git/packages/components/date-picker/src/date-range-picker.tsx | head -150
# Look for Calendar props interface
rg -n 'calendarProps' git/packages/components/date-picker/src/ -A5 -B2Length of output: 174 🏁 Script executed: #!/bin/bash
# Search for onFocusChange definition
rg -n 'onFocusChange' git/packages/components/date-picker/src/ -B3 -A3Length of output: 80 🏁 Script executed: #!/bin/bash
# Inspect DateRangePicker component with correct path
cat packages/components/date-picker/src/date-range-picker.tsx | head -200
# Search for onFocusChange in date-picker component files
rg -n 'onFocusChange' packages/components/date-picker/src/ -B3 -A3Length of output: 4003 🏁 Script executed: #!/bin/bash
# Search use-date-range-picker for onFocusChange
cat packages/components/date-picker/src/use-date-range-picker.ts | grep -n 'onFocusChange' -B5 -A5
# Check RangeCalendar component
fd -e tsx -e ts 'range-calendar' packages/components/
# Search all onFocusChange references in date-picker
rg 'onFocusChange' packages/components/date-picker/Length of output: 2406 🏁 Script executed: #!/bin/bash
# Inspect RangeCalendar component
cat packages/components/calendar/src/range-calendar.tsx | head -200
# Search use-range-calendar for onFocusChange type definition
rg -n 'onFocusChange' packages/components/calendar/src/use-range-calendar.ts -B3 -A3Length of output: 1089 🏁 Script executed: #!/bin/bash
# Get full use-range-calendar.ts file to find interface definition
cat packages/components/calendar/src/use-range-calendar.ts | head -300
# Also search for UseRangeCalendarProps interface
rg -n 'interface UseRangeCalendarProps|export.*UseRangeCalendarProps' packages/components/calendar/src/use-range-calendar.ts -A20Length of output: 4479 🌐 Web query: 💡 Result: The RangeCalendar onFocusChange signature is: Sources: React Aria RangeCalendar docs. [1][2] Update onFocusChange description to reflect accurate API behavior. The documented description is incorrect. React Aria's RangeCalendar onFocusChange receives a single The callback simply tracks which date is focused in the calendar—the developer controls how to apply that focused date to their state (e.g., assign to start date if empty, otherwise to end date). Replace the description with: 🤖 Prompt for AI Agents |
||
| default: "-" | ||
| }, | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: onFocusChange incorrectly overwrites date values with strings.
The
valparameter inonFocusChangerepresents the focus state ("start"or"end"), not a date value. Lines 101 and 103 incorrectly setstart: valandend: val, which overwrites the date objects with strings.Apply this fix to preserve the actual date values:
Or, if the intent is only to track which field has focus (not update dates), remove the handler entirely or use a different callback.
🤖 Prompt for AI Agents