-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[FilledInput][material-next] Add FilledInput component #39307
[FilledInput][material-next] Add FilledInput component #39307
Conversation
Netlify deploy previewhttps://deploy-preview-39307--material-ui.netlify.app/ @mui/material-next: parsed: +0.31% , gzip: +0.94% Bundle size reportDetails of bundle changes (Toolpad) |
c202d8a
to
05d05c6
Compare
30a908b
to
8e764ab
Compare
fb9afbb
to
08e77aa
Compare
3347073
to
51252cf
Compare
51252cf
to
1493a04
Compare
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.
Nice! left some questions and suggestions 😊
packages/mui-material-next/src/FormControl/FormControl.test.tsx
Outdated
Show resolved
Hide resolved
|
||
const RootSlot = slots.root ?? components.Root ?? FilledInputRoot; | ||
const InputSlot = slots.input ?? components.Input ?? FilledInputInput; | ||
if (multiline) { |
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.
What was the error? 🤔
packages/mui-material-next/src/FilledInput/FilledInput.test.tsx
Outdated
Show resolved
Hide resolved
c362850
to
6c233b2
Compare
type, | ||
}, | ||
externalForwardedProps: other, | ||
ownerState: ownerState as FilledInputOwnerState & InputBaseOwnerState, |
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.
Shouldn't FilledInputOwnerState include the InputBaseOwnerState fields? This shouldn't be necessary then.
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.
There are some common properties, but even more differences as these OwnerState
s include their OwnProps
which is where the differences are:
material-ui/packages/mui-material-next/src/FilledInput/FilledInput.types.ts
Lines 67 to 73 in f46a4c2
export type FilledInputOwnerState = Simplify< | |
FilledInputOwnProps & { | |
disableUnderline?: boolean; | |
fullWidth: boolean; | |
inputComponent: React.ElementType; | |
multiline: boolean; | |
type?: React.InputHTMLAttributes<HTMLInputElement>['type']; |
(btw the TS error here was also quite intimidating 😂 luckily I found this trick from Joy https://github.com/mui/material-ui/blob/master/packages/mui-joy/src/Menu/Menu.tsx#L156)
|
||
const RootSlot = slots.root ?? components.Root ?? FilledInputRoot; | ||
const InputSlot = slots.input ?? components.Input ?? FilledInputInput; | ||
if (multiline) { |
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.
<InputBase
slots={{ root: Root, input: Input }}
slotProps={{
input: inputProps,
}}
type={type}
multiline={multiline}
{...rootProps}
/>
The error you see comes from the fact you're providing the type
prop, which makes TS choose the overload with multiline=false
. And since the multiline
variable can be true | false
, TS complains.
It would be nice if we could do
type={multiline ? undefined : type}
multiline={multiline}
but TS isn't that smart, apparently :)
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.
I am ok with making the types flat, however, can we do some runtime warning if the users does not provide multiline
, but they provide some of the props that makes sense only if the component rendered is textarea?
injectedProps = props; | ||
const { ownerState, ...other } = props; | ||
return <input ref={ref} {...other} />; | ||
}); | ||
|
||
render(<InputBase inputComponent={MyInputBase} />); | ||
|
||
expect(typeof injectedProps.onBlur).to.equal('function'); | ||
expect(typeof injectedProps.onFocus).to.equal('function'); | ||
if (injectedProps) { |
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.
When would this be undefined? Are we accidentally skipping these expect statements?
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.
@mnajdova Fixed ~ it's not needed, I accidentally left it there while trying to fix some TS issue!
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.
Perfect, thanks!
7557cb4
to
1797c40
Compare
Good idea ~ added in 2f6bc51 |
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.
Great work! 🚀
Part of #39052
FormControl.tests
andInputBase.tests
) to TS, and adoptinguseSlotProps
FilledInput
,FormControl
, andInputBase
: one depends onSelect
, the other depends onTextField
/experiments/md3/inputs
Preview: https://deploy-preview-39307--material-ui.netlify.app/experiments/md3/inputs/