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

[TextareaAutosize] Convert code to TypeScript #35862

Merged
merged 20 commits into from Feb 16, 2023

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jan 18, 2023

closes: #34721

@mui-bot
Copy link

mui-bot commented Jan 18, 2023

Netlify deploy preview

https://deploy-preview-35862--material-ui.netlify.app/

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against b734b86

@sai6855 sai6855 changed the title [TextareaAutoSize] convert to typescript [TextareaAutoSize] Convert TextareaAutoSize to typescript Jan 18, 2023
@@ -28,20 +29,27 @@ describe('<TextareaAutosize />', () => {
'ownerStatePropagation',
'propsSpread',
'refForwarding',
'rootClass',
Copy link
Contributor Author

@sai6855 sai6855 Jan 18, 2023

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.

const fullSuite = {
componentProp: testComponentProp,
slotsProp: testSlotsProp,
slotPropsProp: testSlotPropsProp,
slotPropsCallbacks: testSlotPropsCallbacks,
mergeClassName: testClassName,
propsSpread: testPropForwarding,
reactTestRenderer: testReactTestRenderer,
refForwarding: describeRef,
ownerStatePropagation: testOwnerStatePropagation,
};

@sai6855 sai6855 changed the title [TextareaAutoSize] Convert TextareaAutoSize to typescript [TextareaAutoSize] Convert Code to typescript Jan 18, 2023
@zannager zannager added the component: TextareaAutosize The React component. label Jan 19, 2023
Comment on lines 81 to 86
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');
Copy link
Contributor Author

@sai6855 sai6855 Jan 20, 2023

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

@sai6855 sai6855 requested review from oliviertassinari and michaldudak and removed request for michaldudak and oliviertassinari January 30, 2023 12:00
@michaldudak
Copy link
Member

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 getStyleValue to:

function getStyleValue(value: string) {
  return parseInt(value, 10) || 0;
}

and call it with just getStyleValue(computedStyle.paddingBottom) instead of using [] for property access.

Unless there's a good reason why the current implementation looks as it does (cc @oliviertassinari).

@oliviertassinari
Copy link
Member

and call it with just getStyleValue(computedStyle.paddingBottom) instead of using [] for property access. 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:

  • computedStyle.getPropertyValue('transform')
  • const firstChildMarginLeft = parseToNumber(firstChildComputedStyle.marginLeft);
  • getStyleValue(computedStyle, 'padding-bottom')

They behave almost identically:

}

return () => {
handleResize.clear();
containerWindow.removeEventListener('resize', handleResize);
if (containerWindow) {
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@sai6855 sai6855 Feb 15, 2023

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

@sai6855
Copy link
Contributor Author

sai6855 commented Feb 15, 2023

removed kebabtypes as per #35862 (comment), but hold on to (#35862 (comment)) change

@michaldudak
Copy link
Member

Could you please merge in the latest master? This should help with the Argos CI check.

@sai6855
Copy link
Contributor Author

sai6855 commented Feb 16, 2023

@michaldudak done, merged lastest master

Copy link
Member

@michaldudak michaldudak left a 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!

@michaldudak michaldudak changed the title [TextareaAutoSize] Convert Code to typescript [TextareaAutoSize] Convert code to TypeScript Feb 16, 2023
@michaldudak michaldudak changed the title [TextareaAutoSize] Convert code to TypeScript [TextareaAutosize] Convert code to TypeScript Feb 16, 2023
@michaldudak michaldudak merged commit 0e71c00 into mui:master Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TextareaAutosize][base] Convert code to TypeScript
5 participants