Skip to content

Conversation

@michelengelen
Copy link
Member

@michelengelen michelengelen commented Nov 6, 2025

This pull request introduces a new source property to the date/time picker lifecycle and event handler context, enabling clearer differentiation between changes initiated by the picker UI and those from direct field input.

The documentation is updated to explain this addition, and the codebase is refactored to consistently set and propagate the source property throughout picker interactions and event handlers.

Fixes #19830

…tation

Signed-off-by: michel <jsnerdic@gmail.com>
@michelengelen michelengelen self-assigned this Nov 6, 2025
@michelengelen michelengelen added scope: pickers Changes related to the date/time pickers. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Nov 6, 2025
@mui-bot
Copy link

mui-bot commented Nov 6, 2025

Deploy preview: https://deploy-preview-20234--material-ui-x.netlify.app/

Updated pages:

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 🔺+204B(+0.09%) 🔺+53B(+0.08%)
@mui/x-date-pickers-pro 🔺+203B(+0.06%) 🔺+37B(+0.04%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)

Details of bundle changes

Generated by 🚫 dangerJS against d3dcc2e

shortcut?: PickersShortcutsItemContext;
/**
* Source of the change.
* If not provided, it will be inferred as "picker" when a `shortcut` is present, otherwise defaults to "field".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this inferrance?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did test this with the demos from the docs, so I think it should be picking up everything as it is intended to do. Or did I miss something?

Screen.Recording.2025-11-06.at.14.03.35.mov

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you think it would make sense to also include 'shortcut' as an option?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see
It feels fragile to me. If tomorrow we add a new UI that updates the value, we can easily have it flagged as source: "field" by mistake.

WDYT about instead making this property required in SetValueActionOptions?
Or at least put picker as the default since it's the one triggered by all UIs except the field, and then have the field explicitely put source: "field".

Side note, maybe it's worth being more precise thant picker (have source: "field" | "view" | "shortcut" | ...
But no strong preference here.

Copy link
Member Author

@michelengelen michelengelen Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that makes sense ... so, top get this straight the proposal would be this:

export interface SetValueActionOptions<TError = string | null> {
  ...
  /**
   * Source of the change.
   * @default 'picker'
   */
  source: 'picker' | 'field' | 'view' | 'shortcut';
  ...
}

Correct?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flaviendelangle I have added a new commit with a similar approach to what you suggested, but with this it is even possible to create more general handling if the granular approach is too much. So basically I kept the source as is, but extended that with more granular sub-sources, e.g. 'picker:actionBar:ok'. That way the user can determine easily where that change came from. WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const clearValue = useEventCallback(() =>
    setValue(valueManager.emptyValue, { source: 'picker:actionBar:clear' }),
  );

This is wrong, clearValue can be called from anywhere, not only from the action bar.

WDYT about keeping "field" | "view" | "unknown"
For those two, we know that the change has to come from the requested place (for field it's the field that sets the source, for the view, the method is passed directly to the view and is not accessible elsewhere).
And then we can see if people ask for other places and react accordingly.

I have no idea if actionBar:ok is usefull, or if actionBar would be enough, so I propose to wait and see what users want 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michelengelen looks good to me 👌

Just one last question: what is the reasoning behind using "picker" rather than "view"? Can it be used from elsewhere than the view?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason. Maybe because it is a "Picker" overlay? Not against naming it view though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main struggle with "picker" is that everything is "picker" since the component itself is a picker.
At least it's the nomenclature that we are using. We have the field (the input to type the date with the keyboard) and the view (the UI to select the date with the mouse). Together (and with the shortcuts, the toolbar, the tabs and the action bar) they form the picker component.

michelengelen and others added 12 commits November 7, 2025 11:48
…ated related documentation

Signed-off-by: michel <jsnerdic@gmail.com>
Signed-off-by: michel <jsnerdic@gmail.com>
Signed-off-by: michel <jsnerdic@gmail.com>
… documentation

Signed-off-by: michel <jsnerdic@gmail.com>
Signed-off-by: michel <jsnerdic@gmail.com>
…cceptances

Signed-off-by: michel <jsnerdic@gmail.com>
Signed-off-by: michel <jsnerdic@gmail.com>
Signed-off-by: michel <jsnerdic@gmail.com>
@michelengelen michelengelen enabled auto-merge (squash) November 11, 2025 14:17
michelengelen and others added 2 commits November 12, 2025 14:26
Co-authored-by: Flavien DELANGLE <flaviendelangle@gmail.com>
Signed-off-by: Michel Engelen <32863416+michelengelen@users.noreply.github.com>
Signed-off-by: michel <jsnerdic@gmail.com>
@michelengelen michelengelen merged commit 840fad5 into mui:master Nov 12, 2025
21 checks passed
@michelengelen michelengelen deleted the feature/19830 branch November 12, 2025 15:03
bernardobelchior added a commit to bernardobelchior/mui-x that referenced this pull request Nov 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: pickers Changes related to the date/time pickers. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[pickers] onAccept is fired before entering the complete date when using the input field

3 participants