[pickers] Create a single setValue
method used by all the parts of the picker to update the value
#16059
Labels
breaking change
component: pickers
This is the name of the generic UI component, not the React module!
Problem
Currently, we have tons of way to update the value of the picker, each with its own signature:
View update:
Field update:
Action update:
Update from the toolbar (same as the view update)
Update from the shortcut
Proposal
Create a single method
setValue
that would be exposed by the picker context and that would replace all of the currentmethods.
It would have an options methods that allow to handle all the behaviors currently supported:
The exact shape of
SetValueActionOptions
might evolve as we migrate all the methods, but the current one seems to solve all the use cases (except theshallow
update of the Time Clock, but I don't think it should usesetValue
).Side notes
Some methods can be replaced on the public API during the alpha, other can be implemented internally using
setValue
but keep there current signature depending on the migration pace.The actions (
onClear
,onAccept
, ...) are still exposed because people currently don't have a way to access the various date in the state (the last published value, the last comitted value, ...) so they can't reproduce their behavior. But those methods all take 0 parameter so it's not a problem for the consistency of our API. We can discuss later if we prefer to always enforce the usage ofsetValue
and provide the tools to do it.Excluded work
This issue does not cover any change to the
onChange
props of the component that can be used as standalone.If a component cannot be used as standalone (e.g: the toolbar and shortcuts slots), then they always use
setValue
from the context and don't have anonChange
prop anymore.But if they can be used as standalone (e.g:
<DateCalendar />
,<TimField />
, etc...), then they need to still have anonChange
prop.I would like to align all those
onChange
prop to be similar to theonChange
of the picker (like the field is today), but it's outside of the scope of this issue and can wait for v9.The text was updated successfully, but these errors were encountered: