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

Skeleton provides error in <p> tags #19210

Closed
2 tasks done
ximex opened this issue Jan 13, 2020 · 6 comments · Fixed by #19278
Closed
2 tasks done

Skeleton provides error in <p> tags #19210

ximex opened this issue Jan 13, 2020 · 6 comments · Fixed by #19278
Labels
component: skeleton This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request

Comments

@ximex
Copy link

ximex commented Jan 13, 2020

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Got an error in the logs

Expected Behavior 🤔

No error logs

Steps to Reproduce 🕹

Put a Skeleton in a ListItemText secondary prop. Than i got error logs in develop mode.
It's because a <div> in a <p> (Secondary Typography) is invalid

Your Environment 🌎

Tech Version
Material-UI v4.8.3
React v16.11.0
Material-UI/lab 4.0.0-alpha.39

Solution

I think a skeletion variant=text should be <span> instead of a <div>.

@oliviertassinari oliviertassinari added the component: skeleton This is the name of the generic UI component, not the React module! label Jan 13, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 13, 2020

@ximex What do you think of this diff?

diff --git a/packages/material-ui-lab/src/Skeleton/Skeleton.js b/packages/material-ui-lab/src/Skeleton/Skeleton.js
index c4696edc7..56b0ecf51 100644
--- a/packages/material-ui-lab/src/Skeleton/Skeleton.js
+++ b/packages/material-ui-lab/src/Skeleton/Skeleton.js
@@ -74,7 +74,7 @@ const Skeleton = React.forwardRef(function Skeleton(props, ref) {
     animation = 'pulse',
     classes,
     className,
-    component: Component = 'div',
+    component: Component = 'span',
     height,
     variant = 'text',
     width,

Using a span seems to be a frequent approach:

Do you want to submit a pull request? :)

@oliviertassinari oliviertassinari added the good first issue Great for first contributions. Enable to learn the contribution process. label Jan 13, 2020
@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 13, 2020

Note, the issue resonates with this comment: #7223 (comment) (button > div issue, CircularProgress). We could even address it at the same time.

@oliviertassinari oliviertassinari added the new feature New feature or request label Jan 13, 2020
@ximex
Copy link
Author

ximex commented Jan 13, 2020

or this way?

diff --git a/packages/material-ui-lab/src/Skeleton/Skeleton.js b/packages/material-ui-lab/src/Skeleton/Skeleton.js
index c4696edc7..56b0ecf51 100644
--- a/packages/material-ui-lab/src/Skeleton/Skeleton.js
+++ b/packages/material-ui-lab/src/Skeleton/Skeleton.js
@@ -74,7 +74,7 @@ const Skeleton = React.forwardRef(function Skeleton(props, ref) {
     animation = 'pulse',
     classes,
     className,
-    component: Component = 'div',
+    component: Component = props.variant === 'text' ? 'span' : 'div',
     height,
     variant = 'text',
     width,

a div makes sense for rect and circle

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 13, 2020

I'm wondering. Would being consistent be better? We render it as a display block no matter the element.

@ximex
Copy link
Author

ximex commented Jan 13, 2020

yes the rendering is display: block. but the semantic of the html would be more correct if we use a div for block things and span for text

@oliviertassinari
Copy link
Member

oliviertassinari commented Jan 13, 2020

OK, fair point. @ximex feel free to go ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: skeleton This is the name of the generic UI component, not the React module! good first issue Great for first contributions. Enable to learn the contribution process. new feature New feature or request
Projects
None yet
2 participants