themesberg / themesberg/flowbite-react
Datepicker is not allowing clearing date
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.1k
- Forks
- 506
- PR merge metrics
- No merged PRs in 30d
Description
- I have searched the Issues to see if this bug has already been reported
- I have tested the latest version
Summary
Currently, the Datepicker component in Flowbite-React allows users to select a date, but lacks a fully functional clear button that can reset the date to null. The clear button only resets the date to the original value. I propose adding a flag like isClearAction to the onSelectedDateChanged callback function. This flag would be set to true when the clear button is used, allowing developers to explicitly handle the clear action by setting the date to null if desired.
Example implementation:
<Controller
control={control}
name="birthday"
render={({ field: { onChange, value } }) => (
<Datepicker
onSelectedDateChanged={(date, isClear) => {
if (isClear) {
onChange(null); // Explicitly handle clear action
return;
}
onChange(date); // Handle date change normally
}}
placeholder="Please enter date"
ref={elementRef}
value={value ? moment(value).format('YYYY-MM-DD') : ''}
/>
)}
/>
This feature would enable developers to easily implement scenarios where a user might need to completely remove a previously selected date.
Context
In various applications, especially in forms involving date entries like event planning, user registrations, or bookings, having the capability to clear a date completely is crucial. Currently, without this feature, users of our application cannot remove a date once selected; they can only change it. This limitation affects the flexibility and user experience of the application. By implementing this feature, we will provide a more robust and intuitive interaction for users who need to reset their date selections entirely.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the Datepicker component and trace how its clear button invokes onSelectedDateChanged. Confirm the callback's current arguments and how the original value is restored, then define the clear-action behavior described in the issue and verify that selecting a date still behaves normally. Done means users can clear an existing date and consumers can distinguish clearing from selecting a date.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100