-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
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
[Joy] Use native html for root slot #33773
Conversation
@mui/joy: parsed: -0.22% 😍, gzip: -0.20% 😍 |
id, | ||
name, | ||
onClick, | ||
onChange, | ||
onKeyDown, | ||
onKeyUp, | ||
onFocus, | ||
onBlur, | ||
placeholder, | ||
readOnly, | ||
required, | ||
type = 'text', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleaner code 🎉
const propsToForward = { | ||
'aria-describedby': ariaDescribedby, | ||
'aria-label': ariaLabel, | ||
'aria-labelledby': ariaLabelledby, | ||
autoComplete, | ||
autoFocus, | ||
id, | ||
onKeyDown, | ||
onKeyUp, | ||
name, | ||
placeholder, | ||
readOnly, | ||
type, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for all of these anymore.
// props to forward to the button (all handlers should go through componentsProps.button) | ||
'aria-describedby': ariaDescribedby, | ||
'aria-label': ariaLabel, | ||
'aria-labelledby': ariaLabelledby, | ||
id, | ||
name, | ||
sx, | ||
...other | ||
} = props as typeof inProps & { | ||
// need to cast types because SelectOwnProps does not have these properties | ||
'aria-describedby'?: string; | ||
'aria-label'?: string; | ||
'aria-labelledby'?: string; | ||
id?: string; | ||
name?: string; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look at this mess 🥲
This conformance test
I wonder if the best solution here is to unbundle. If it's painful to target a child element, then maybe it should be its own React component? We encourage most people to use the TextField, and to look into
I think that regardless of this proposal, in some cases, it would be beneficial to flatten the slots, making child slots available to the parent. If we move in this direction, to make sure it's compatible with making the same change in Material UI v6 (that there are no hidden constraints that we don't see). Also, I have an impression of déjà vu, I suspect we can find GitHub issues that talks about this problem in the history. |
Motivation
Our
Input
andSelect
requires adiv
for creating the layout because we want to make it easy to add styles and start/end decorators. Conventionally, all the props are spread to thediv
(defined as theroot
element), which makes the DX sometimes really bad:Related issues:
Proposal
I think 99.99% of developers want to pass props/ref to the
input
element, not thediv
so why don't we mark theinput
as the root slot so that it still follows our convention and add a special note that theroot
slot does not need to be the uppermost parent of the component.This reduces some complexity in the code as well because we don't need to define which prop should be forwarded to
input
.The result will be like this:
However, the
sx
prop is a special prop. It always goes to the uppermost of the component for styling purposes. (I tried and it gives a lot better experience).cc @flaviendelangle What do you think?
close #33738