-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[pickers] DatePicker: adding a inputAdornment when a condition is met #9285
Comments
We are currently working on providing an out-of-the-box solution for clearing the input. 😉 |
Thanks for answering so quickly! The out-of-the-box solution sounds awesome! As for the merging strategy: no, I haven't seen that. Will check it out in detail on Monday. But right away I am wondering how to reach the slots={{
textField: {
renderInput: ({ InputProps, ...params }) => (
<TextField
{...params}
InputProps={{
...InputProps,
endAdornment: (
<React.Fragment>
{this.state.date && (<IconButton onClick={(e) => {
e.stopPropagation();
setDate(null);
}}>
<Clear />
</IconButton>
)}
{InputProps?.endAdornment}
</React.Fragment>
),
}}
/>)
}
}} But that cause |
OK, the solution is something like this:
Though this does break the positioning of the popover of the |
Hello @TheRealCuran, thank you for providing a solution on your own. Your version was missing the Don't forget to always provide slot item as a separate component instead of a direct render function, which would be re-rendered each time the root component is rendered. |
Thanks for the example! Actually I had the spread of The note about providing a distinct component was the missing part, now the anchoring of the popover works again! This ticket can be closed as far as I am concerned, though it would be nice if the documentation could be expanded a bit. |
Which particular documentation do you feel needs more information or examples? |
IMHO this section in the documentation (it is what you find, when you look for |
We've decided to improve the documentation on The proposed solution was to:
|
That sounds great! I don't really see the mention (only one hit for https://mui.com/x/react-date-pickers/custom-components/ however goes into more detail and would probably have been enough for me. Once you feel all the updates to the docs have been merged, you can feel free to close this issue. Thanks again, for taking care of this! |
Closed by #10421 |
How did we do @TheRealCuran? |
I was having issue that the each time the component render it would loose its state and ref, converting the textfield render function to a separate component helped. thanks! But there's still one problem the picker value doesn't change on first input, any reason why? |
Could you clarify what you mean by |
I realized that my initial value was a string, which made it invalid. I converted it to a date instance, which resolved the issue. |
Order ID or Support key 💳 (optional)
61706
Duplicates
Latest version
The problem in depth 🔍
We have a search interface where people can pick dates to refine the search. When a date is selected, we add the
<Clear />
SVG icon and allow users to easily reset the filter. With MUI-X 5.x this worked with the following code:Now, with MUI-X 6
renderInput
is gone and one should useslotProps
/slots
. I tried rewriting this withslotProps
but are failing to even manage to get the<Clear />
icon to show (not to mention in addition to the default Icon for opening the picker). The only thing I can manage reliably is to move the postion around – it looks to me like mychildren
parameter gets overwritten. Similar results withslots
and trying to basically use the old code on theTextField
in there.For reference the code with
slotProps
(which should at least replace icon, but doesn't do even that):I am pretty sure I have the correct slot here, since when I change
position: 'end'
toposition: 'start'
I can see it moving to the front on selecting a date. But still, the<Clear />
icon stays invisible.And I have not found anything in the documentation that might help me. Can somebody please point me in the right direction so I can finish the upgrade to MUI-X 6.x? Bonus points if we can show the clear icon in addition to the picker icon again. Thanks.
P.S.: This might also be a bug and may or may not be related to #8322.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: