[pickers] Introduce a new concept of manager
#15395
Labels
component: pickers
This is the name of the generic UI component, not the React module!
new feature
New feature or request
Extracted from #14496 and #14718
Goals
The goal is to decouple our logic and the UI by gathering all the logic specific to a given value type inside a single object.
The end goal would be to be able to create a single unstyled field component instead of six and a single unstyled picker instead of six. This field and picker component would receive the
manager
as a prop.This new object is part of the public API because people would have to pass it to the field and pickers built with the Base UI DX.
DX
Initialization
The Date and Time Pickers package would expose one manager per family of component (
useDateManager
,useTimeManager
,useDateTimeManager
,useDateRangeManager
,useTimeRangeManager
,useDateTimeRangeManager
).The non-range managers hooks only take
enableAccessibleFieldDOMStructure
as a parameter (it's only needed for typing reasons).The range managers hooks take
enableAccessibleFieldDOMStructure
anddateSeparator
as a parameter (just like we havedateSeparator
today inuseRangeFieldValueManager
).Usage in our codebase
Interact with the value
The current
valueManager
andfieldValueManager
are stored inmanager.internal_valueManager
andmanager.internal_fieldValueManager
. I would like to keep those APIs private and I think the prefix makes that clear enough.We can then access its properties as follow:
I plan to merge both in a single object at some point because they would now both be owned by the same parent object. But it can be done in a standalone PR.
Validate the value
We can still import the
validator
directly, but in our codebase we should probably always use it through its manager:In the future we could imagine passing the
manager
touseValidator
instead but for now passing thevalidator
directly works very well.Apply the defaults to the field internal props
This logic is currently handed by each field hook (
useDateField
,useTimeField
,useSingleInputDateRangeField
, etc...). With the adapter, we can remove this logic and instead move it insideuseField
which would now receive the internal props without the defaults applied.Apply the defaults to the picker internal props
TODO (need to have a clearer vision of the DX for the unstyled pickers and we probably have to introduce a notion of
internalProps
/forwardedProps
like on the field before).Get the
aria-text
for the opening triggerRight now this logic is defined in the picker component (
DesktopDatePicker
andMobileDatePicker
for instance), and by the field after #15671.This would allow field with custom UX to easily have a valid aria label.
Impact on our codebase
Field
useField
will be replaced by a newPickerField
component in the future (which will take advantage of themanager
). So migratinguseField
to the new manager will smoother the transition toPickerField
Picker
useDesktopPicker
(and equivalents) will be replaced by the upcomingPicker
component (or other DX, this one is very unclear for now) in the future (which will take advantage of themanager
). So migratinguseDesktopPicker
(and equivalent) to the new manager will smoother the transition toPicker
Impact on the typing
Point 4 of #14823
This one needs more exploration to confirm that it improves the readability of our codebase AND the readability of our public APIs.
The idea is, on certain interfaces, to replace all the generics that can be inferred from the manager.
The main advantage is too reduce the amount of generics and not have to add a new one everytime we need a new info inside those interfaces.
For example:
Usage by the community
This part needs to be clarified.
You can have a look at #14496 (comment) and #14718 for more details about the new DX.
Migrate to the manager
This list will probably evolve but gives an idea of the work:
manager
#15339useDateField
&co hooks to use the managers => [pickers] Introduce a new concept ofmanager
#15339useField
to use the managersuseField
+useDesktopPicker
&co hooks to use the managers forvalueManager
/valueType
andvalidator
(not for applying the default props and other behaviors yet)getOpenDialogAriaText
in the managers and use it inuseDesktopPicker
&cpThe text was updated successfully, but these errors were encountered: