-
-
Notifications
You must be signed in to change notification settings - Fork 444
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 is generating TextInput contains an input of type text with both value and defaultValue #1511
Comments
I've got the same issue, is there any possible way to avoid that error occurency? Context |
Yeah, its broken. Also, Does the onChange work for somebody? |
It's still broken, I observed a similar behavior... Depending on which options you're using (e.g. Initial SituationFirst, sorry for the long text, but that's the detailed analysis. As far as I can tell, I'm happy to disagree, but that's the problem. Basically, the component works even as controlled input, meaning the state can be controlled with // Test.tsx
import { useState } from "react";
import { Datepicker } from "flowbite-react";
export default function Test() {
const [date, setDate] = useState<Date | null>(null);
return (
<form>
<Datepicker
value={date}
onChange={(newDate) => setDate(newDate)}
placeholder="Select date"
/>
</form>
);
} In this scenario we have a controlled component (See Controlled Date/Datepicker.) and no date should be selected by default, hence the selected value should be null. At first glance, it seems to work. The internally used text field component is empty and instead the placeholder is shown. But when you select a date using the picker, a warning is thrown. First Warning
The reason for this seems to be that the value for the internal text field is recalculated internally (See Datepicker.tsx:261). If // Datepicker.tsx
const displayValue = value === null ? label : getFormattedDate(language, selectedDate || new Date());
...
<TextInput
...
value={displayValue}
/> Anyways, if you decide to add the label property (e.g. Aftereffect
The reason here is that the component internally calculates the // Datepicker.tsx
const initialDate = defaultValue ? getFirstDateInRange(defaultValue, minDate, maxDate) : null;
...
<TextInput
...
defaultValue={initialDate ? getFormattedDate(language, initialDate) : label}
/> PS: I would also be willing to fix the issue myself or rewrite the code once the solution has been discussed. |
@MuellerConstantin that's a very thorough breakdown of the issue, thank u! The next chapter after the #1498 is merged, is to start thinking of really good headless component library we can use, tbh I am really tired of the issues a complex component like So I say and suggest that |
@SutuSebastian Is this a final decision? Because in my opinion it shouldn't be that hard to address this issue, I would address it myself. Of course, I don't know if there are other problems with the component that are more difficult to fix. |
@SutuSebastian I reached the same conclusion and went with react-day-picker. |
Going headless for really complex components it's for sure, that is why I'm suggesting not to spend a serious amount of time on this, because any fixes brought to this component will only live until the headless approach is implemented. Feel free to contribute with a fix to this at ur own pace 🚀 |
I am initializing the Datepicker to be empty, however, I am getting a warning on the console with: _TextInput contains an input of type text with both value and defaultValue props. Input elements must be either controlled or uncontrolled (specify either the value prop, or the defaultValue prop, but not both).
Changing the
label to =" "
make the warning go awayThe text was updated successfully, but these errors were encountered: