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

[base-ui][material-ui][TextareaAutosize] Fix inline style not getting applied #41369

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/mui-base/src/TextareaAutosize/TextareaAutosize.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,17 @@ describe('<TextareaAutosize />', () => {
expect(input.style).to.have.property('height', `${lineHeight * 2}px`);
});
});

it('should apply the inline styles using the "style" prop', function test() {
if (/jsdom/.test(window.navigator.userAgent)) {
this.skip();
}

const { container } = render(<TextareaAutosize style={{ backgroundColor: 'yellow' }} />);
const input = container.querySelector<HTMLTextAreaElement>('textarea')!;
Comment on lines +467 to +468
Copy link
Member

@oliviertassinari oliviertassinari Mar 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using the screen. We are moving tests as much as possible to rely on global queries. This is purely to keep the test environment simple. Most of the time, we don't need the notion of a container. We render one element at once on the screen.

Suggested change
const { container } = render(<TextareaAutosize style={{ backgroundColor: 'yellow' }} />);
const input = container.querySelector<HTMLTextAreaElement>('textarea')!;
render(<TextareaAutosize style={{ backgroundColor: 'yellow' }} />);
const input = document.querySelector<HTMLTextAreaElement>('textarea')!;


expect(input).toHaveComputedStyle({
backgroundColor: 'rgb(255, 255, 0)',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const TextareaAutosize = React.forwardRef(function TextareaAutosize(
ref={handleRef}
// Apply the rows prop to get a "correct" first SSR paint
rows={minRows as number}
style={style}
ZeeshanTamboli marked this conversation as resolved.
Show resolved Hide resolved
{...other}
/>
<textarea
Expand Down
Loading