Skip to content
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] slotProps "sx prop does not exist on type" error with custom DatePicker #13171

Open
giavinh79 opened this issue May 18, 2024 · 3 comments
Labels
component: pickers This is the name of the generic UI component, not the React module! customization: css Design CSS customizability docs Improvements or additions to the documentation

Comments

@giavinh79
Copy link

giavinh79 commented May 18, 2024

Steps to reproduce

https://codesandbox.io/p/sandbox/mui-slotprops-types-8v6mfz?file=%2Fsrc%2FDemo.tsx%3A8%2C1

Steps:

  1. See type errors on sx prop

Current behavior

Type errors on sx prop

Expected behavior

sx prop has types and intellisense

Context

Currently on V6 of @mui/x-date-pickers (but issue can be reproduced on latest version of MUI as well) and creating a component wrapping the MUI DatePicker and DateRangePicker components.

The custom component may have sx styles defined internally via slotProps but should allow a consumer to override these styles. The codesandbox has a basic example of this but as you can observe, there are type errors on the sx prop in slotProps.

Your environment

MacOS Sonoma
Chrome Version 125.0.6422.61

Search keywords: sx slotProps typescript DatePicker custom

@giavinh79 giavinh79 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 18, 2024
@giavinh79 giavinh79 changed the title [pickers] sx prop in slotProps does not exist on type error with custom DatePicker [pickers] slotProps "sx prop does not exist on type" error with custom DatePicker May 18, 2024
@zannager zannager added the component: pickers This is the name of the generic UI component, not the React module! label May 20, 2024
@LukasTy LukasTy self-assigned this May 20, 2024
@LukasTy
Copy link
Member

LukasTy commented May 20, 2024

@giavinh79 Thank you for creating this issue! 🙏
The problem stems from the fact that this particular slot supports two ways of passing props:

  • a callback
  • an object

In such case, to replicate/keep the existing behavior you need to use resolveComponentProps to avoid the TS error—and a problem if you'd use a callback in your example.
Please find the updated demo and let me know if you have any further questions regarding this. 😉 👍

@flaviendelangle do you agree that we should improve the documentation in this regard? 🤔
The question is, would it make sense to extend https://mui.com/base-ui/guides/overriding-component-structure/ or create a separate page in X documentation?

@LukasTy LukasTy added status: waiting for author Issue with insufficient information customization: css Design CSS customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 20, 2024
@flaviendelangle
Copy link
Member

This relates a lot to https://mui-org.slack.com/archives/C04U3R2V9UK/p1714135691643129?thread_ts=1714088113.295129&cid=C04U3R2V9UK

base-ui is dropping the slots approach (but @mui/material will keep using it) so the guide might not survive for very long in its current form.

@LukasTy
Copy link
Member

LukasTy commented May 20, 2024

Let this be the issue that we can use as a basis to improve the documentation.
I'm moving it to grooming. 👌

@LukasTy LukasTy removed their assignment May 20, 2024
@LukasTy LukasTy added docs Improvements or additions to the documentation and removed status: waiting for author Issue with insufficient information labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pickers This is the name of the generic UI component, not the React module! customization: css Design CSS customizability docs Improvements or additions to the documentation
Projects
None yet
Development

No branches or pull requests

4 participants