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

Different behavior with Preact on a basic React Material use case (plain TextField) #3717

Closed
1 task
krskrs opened this issue Sep 11, 2022 · 1 comment · Fixed by #3720
Closed
1 task

Different behavior with Preact on a basic React Material use case (plain TextField) #3717

krskrs opened this issue Sep 11, 2022 · 1 comment · Fixed by #3720

Comments

@krskrs
Copy link

krskrs commented Sep 11, 2022

  • Check if updating to the latest Preact version resolves the issue: No

Describe the bug

Steps to reproduce the behavior: (code sandbox below)

I believe I've found a difference with react on a simple React Material UI library use case.

I noticed that in a plain TextBox with a placeholder, the placeholder text and the label overlap when the input gets focus.

Looking further into it I believe I've pinpointed the issue in the data-shrink attribute dynamically set to the label element on getting/losing focus. It looks like Preact is not rendering the data-shrink attribute when its value is false, while it does when it's true. This causes some styles to not be correctly applied and thus the overlap. On React, on the contrary, bot values of the attribute are rendered in the DOM.

https://codesandbox.io/s/late-water-50w2lg?file=/src/index.js PS I've used a class component because the template I found used it, but the same happens with functional components as well

datashrink

Here the data-shrink attribute is missing, while it should be rendered and set to false, for the style rule to kick-in and hide the label.

image

This is on React:

image

I've reported this in case there is something which prevents Preact from rendering that attribute when its value is false. Or if the wrong behavior is due to different root causes, maybe I can also file an issue on their repository.

This should be the relevant part on MUI's code:
https://github.com/mui/material-ui/blob/af3cb56bfc9baa48fa0489f4e1277547d286a887/packages/mui-material/src/InputLabel/InputLabel.js#L119

Thank you and keep up the good work with Preact!

@developit
Copy link
Member

We might want to consider replacing the aria- prefix handling with a simpler dash handling: if a prop name has a dash and is being set as an attribute, don't remove the attribute when the value is false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants