Skip to content
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

DatePicker component defaultDate/clear not working as expected #1039

Closed
2 tasks done
kresimirlesic opened this issue Oct 3, 2023 · 5 comments
Closed
2 tasks done
Labels
🚀 enhancement New feature or request

Comments

@kresimirlesic
Copy link

kresimirlesic commented Oct 3, 2023

  • I have searched the Issues to see if this bug has already been reported
  • I have tested the latest version

Steps to reproduce

Create a default DatePicker component.

Current behavior

Component renders with today's date as the selected one, additionally, clearing out the date sets the selected date to today.

Expected behavior

Component input should be empty. Ideally, placeholder should be displayed if passed in.

@kresimirlesic kresimirlesic changed the title DateTime component defaultDate/clear not working as expected DatePicker component defaultDate/clear not working as expected Oct 3, 2023
@rluders
Copy link
Collaborator

rluders commented Oct 3, 2023

Well, I guess that the Datepicker references that I got were always displaying the "today" date as default. So... It is kind of, not a bug, 'cause it is working as it was programmed to do... but, got it... I guess that makes sense to level it empty sometimes.

@rluders rluders added the 🚀 enhancement New feature or request label Oct 3, 2023
@kresimirlesic
Copy link
Author

kresimirlesic commented Oct 3, 2023

Hey @rluders , thank you for the quick response!

I did have to switch to react-datepicker for the time being until this gets resolved.

The way they do it is with a isClearable props, once you set it to true, you can clear out the field and assign null/undefined values.

... just a food for thought

@rluders rluders mentioned this issue Oct 10, 2023
2 tasks
@mcle0463
Copy link

so if you pass a defaultDate prop then the DatePicker should render with that date selected? Is that the expected behavior? if so i am having this issue as well

ddiasfront added a commit to ddiasfront/flowbite-react that referenced this issue Dec 20, 2023
…r clicking clear button"

A new optional property with a default value was added to the component definition to define what
text the developer wants to use when the datepicker component has its date cleared ( which means no
date selected ).

themesberg#1039 themesberg#1167
@MiroslavPetrik
Copy link
Contributor

MiroslavPetrik commented Mar 14, 2024

One workaround for controlled Datepicker is that you can set value and placeholder props like this:

  const emptyProps = !value
    ? {
        value: "",
        placeholder: "Please select a date",
      }
    : {};

<Datepicker {...emptyProps } />

The "" value overrides the default formatted date, which will enable the native placeholder to be displayed...

But yeah, the Datepicker will still have its internal value.
Good idea to make the Datepicker controlled as well.

@taskrider2022
Copy link

A isClear callback will be nice to set the date to null|undefined

In my case I will add a datepicker that is not mandatory to fill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants