-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[TextareaAutosize] Convert code to TypeScript #35862
Conversation
Netlify deploy previewhttps://deploy-preview-35862--material-ui.netlify.app/ Bundle size report |
packages/mui-base/src/TextareaAutosize/TextareaAutosize.test.tsx
Outdated
Show resolved
Hide resolved
@@ -28,20 +29,27 @@ describe('<TextareaAutosize />', () => { | |||
'ownerStatePropagation', | |||
'propsSpread', | |||
'refForwarding', | |||
'rootClass', |
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.
'rootClass' is not present in fullSuite
, hence removed to make typescript happy.
material-ui/test/utils/describeConformanceUnstyled.tsx
Lines 321 to 332 in f13e534
const fullSuite = { | |
componentProp: testComponentProp, | |
slotsProp: testSlotsProp, | |
slotPropsProp: testSlotPropsProp, | |
slotPropsCallbacks: testSlotPropsCallbacks, | |
mergeClassName: testClassName, | |
propsSpread: testPropForwarding, | |
reactTestRenderer: testReactTestRenderer, | |
refForwarding: describeRef, | |
ownerStatePropagation: testOwnerStatePropagation, | |
}; | |
9704d7c
to
beb368e
Compare
const { container } = render(<TextareaAutosize />); | ||
const input = container.querySelector<HTMLTextAreaElement>('textarea[aria-hidden=null]')!; | ||
const shadow = container.querySelector('textarea[aria-hidden=true]')!; | ||
expect(input.style).to.have.property('height', ''); | ||
expect(input.style).to.have.property('overflow', ''); | ||
|
||
expect(input.style).to.have.property('height', '0px'); | ||
expect(input.style).to.have.property('overflow', 'hidden'); |
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.
height
and overflow
values are changed from empty strings to '0px' and 'hidden' because previously getComputedStyleStub
was using object
and setLayout is mutating this object in below line and setting styles to {height:"",overflow:""}, this is not expected. now since Map
is being used in place of object we came to know about this bug.
Just for reference i'm attaching codesandbox demo https://codesandbox.io/s/stoic-darkness-t1jp9o?file=/demo.js , which renders just TextAreaAutoSize, On inspecting textarea[aria-hidden=true],textarea[aria-hidden=null]
elements , you can see height and overflow are indeed '0px' and 'hidden'.
cc @michaldudak
The KebabKeys type looks pretty clever, but I wonder if we can not use it at all (it's a recursive inferred conditional type - the type checker would be happy we save it from doing this work 😉). The CSSStyleDeclaration type is defined with camelCase keys and works fine this way. We should be able to simplify the implementation by changing the function getStyleValue(value: string) {
return parseInt(value, 10) || 0;
} and call it with just Unless there's a good reason why the current implementation looks as it does (cc @oliviertassinari). |
Nothing that I recall. Looking at our codebase, we like to do it in all the possible ways 😅. I can find:
They behave almost identically: |
} | ||
|
||
return () => { | ||
handleResize.clear(); | ||
containerWindow.removeEventListener('resize', handleResize); | ||
if (containerWindow) { |
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 would be in favor of removing all the defensive checks. e.g. this one and if (inputRef.current) {
. As far as I know, these are guaranteed to be defined even if TypeScript doesn't know it. We would ship less code.
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.
👍 We haven't seen any bug reports related to not having these checks in the JS version, so it's safe to skip them here as well.
@sai6855 would you mind correcting this? The rest of the PR looks fine to me.
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.
done, removed defensive checks , commit: cb83064 . cc @michaldudak
removed |
aa9b8c5
to
cb83064
Compare
Could you please merge in the latest master? This should help with the Argos CI check. |
@michaldudak done, merged lastest master |
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.
All right! Everything seems to be in order.
Thanks for your work on this!
closes: #34721