Skip to content

[pickers] Refactor owner state typing #17517

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

Merged
merged 18 commits into from
May 1, 2025

Conversation

LukasTy
Copy link
Member

@LukasTy LukasTy commented Apr 23, 2025

Fixes #17297.

Before

Screenshot 2025-04-22 at 16 11 06

After

Screenshot 2025-04-23 at 14 55 26

Open questions

  1. ℹ️ We are not always passing ownerState to the styled elements, which are accessible by styleOverrides.
    This causes issues, because the "contract", that styleOverrides exposes is not "held".
    Q: Should we add the missing ownerState to every styled element available for styleOverrides?
    Resolution: Keeping this situation as is until explicit requests.
  2. ✅ The following components have styled elements and are available through styleOverrides, however, they do not have any ownerState passed to them, not even the root component.
    Q: Should we remove styleOverrides typing for them or pass the ownerState?
    Resolution: Passed some ownerState at least to the root element (defined OwnerState in case of MuiPickersSlideTransition).
    1. MuiDayCalendarSkeleton
    2. MuiPickersFadeTransitionGroup
    3. MuiPickersSlideTransition
    4. MuiPickersToolbarButton
    5. MuiPickersToolbarText

@LukasTy LukasTy added type: bug A bug or unintended behavior in the components. typescript scope: pickers Changes or issues related to the pickers product labels Apr 23, 2025
@LukasTy LukasTy self-assigned this Apr 23, 2025
@mui-bot
Copy link

mui-bot commented Apr 23, 2025

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

Generated by 🚫 dangerJS against 592590d

@@ -9,7 +9,7 @@ import {
openPicker,
stubMatchMedia,
} from 'test/utils/pickers';
import { pickerPopperClasses } from '@mui/x-date-pickers/internals/components/PickerPopper';
import { pickerPopperClasses } from '@mui/x-date-pickers/internals';
Copy link
Member Author

Choose a reason for hiding this comment

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

This wasn't causing issues and, for some reason, didn't even trigger ESLint issue, even though it should have. 🤔

@LukasTy LukasTy marked this pull request as ready for review April 23, 2025 11:56
@LukasTy LukasTy requested a review from flaviendelangle April 23, 2025 11:57
@flaviendelangle
Copy link
Member

flaviendelangle commented Apr 23, 2025

During my ownerState rework, I did not add the ownerState to any element that did not have them.
But yes it should be unified.

For me the question is more: is it worth doing?
If you have bandwitch in the coming days before the bulk of the work starts for the scheduler, I'm fine doing it, but not once we have started the new component 👍

@LukasTy
Copy link
Member Author

LukasTy commented Apr 23, 2025

For me the question is more: is it worth doing?
If you have bandwitch in the coming days before the bulk of the work starts for the scheduler, I'm fine doing it, but not once we have started the new component 👍

@flaviendelangle I have kept the 1st question as is and addressed the 2nd one as I saw best - aligning with the existing syleOverrides definition and passing props as ownerState to avoid redundant context reading.
Only MuiPickersSlideTransition had proper ownerState as I initially missed it - it was used, but not passed to the styled component.

<PickersFadeTransitionGroupRoot className={clsx(classes.root, className)}>
<PickersFadeTransitionGroupRoot
className={clsx(classes.root, className)}
ownerState={{ ...other }}
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 not want the ownerState receiving the children prop, it seemed counter intuitive. 🙈

Copy link
Member

Choose a reason for hiding this comment

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

What is the benefit of spreading here?

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 mean I'm passing ownerState at all?
Or why not store it in a variable and pass it?
P.S. Any styled component needs ownerState to adhere to the exposed styleOverrides contract.

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 have moved the ownerState declaration outside of JSX.

Copy link
Member

Choose a reason for hiding this comment

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

No my question was why ownerState={{ ...other }} instead of ownerState={other}

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, sorry for my "broken brain" that day. 🙈
I will address it with the next PR. 😉

Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 30, 2025
@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Apr 30, 2025
@LukasTy LukasTy requested a review from noraleonte May 1, 2025 10:39
Copy link
Contributor

@noraleonte noraleonte left a comment

Choose a reason for hiding this comment

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

LGTM 👌

@LukasTy LukasTy merged commit cfd1cb3 into mui:master May 1, 2025
21 checks passed
@LukasTy LukasTy deleted the refactor-pickers-owner-state branch May 1, 2025 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: pickers Changes or issues related to the pickers product type: bug A bug or unintended behavior in the components. typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pickers] MuiPickersInputBase report error with customized theme
4 participants