question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow setting the skeleton width and height only while it is being loaded

See original GitHub issue

🚀 Feature request

Since Chakra provides an incredible Skeleton wrapper that works as a Box, it is common to face scenarios where your Skeleton is wrapping an empty content until you fetch the remote data. For those cases, it would be great to have a way to customize the Skeleton width/height while is being loaded without affecting the content box afterwards.

🧱 Problem Statement / Justification

Here is a sample snippet:

      <Skeleton isLoaded={!isLoading}>
        <Heading as="h3" fontSize="18px">
          {company?.name}
        </Heading>
      </Skeleton>

In that snippet (which is pretty common in my project) before fetching company data, the Skeleton component is empty, since it is rendering an undefined child. When it renders in my DOM I simply cannot see the Skeleton at all.

To fix that, I have two options, I can either:

Use a static text fallback (bad):

      <Skeleton isLoaded={!isLoading}>
        <Heading as="h3" fontSize="18px">
          {company?.name ?? 'Sample text'}
        </Heading>
      </Skeleton>

This works, but it is hacky and suboptimal (I can have some issues like running into an error in my request, and them rendering the Sample text instead.

Set the minimum width and height:

      <Skeleton isLoaded={!isLoading} minW="150px" minH="21px">
        <Heading as="h3" fontSize="18px">
          {company?.name}
        </Heading>
      </Skeleton>

This works, but after rending the final component the minW and minH props are passed to the Skeleton box, affecting the behavior of the final rendered component (which is bad). To fix that, I ended up with something like this:

      <Skeleton isLoaded={!isLoading} minW={ isLoading ? '150px' : 'auto' } minH={ isLoading ? '21px' : 'auto' }>
        <Heading as="h3" fontSize="18px">
          {company?.name}
        </Heading>
      </Skeleton>

Which, in my opinion, is hacky.

We should have a prop to set the width and height of the Skeleton only when it is being loaded.

✅ Proposed solution or API

I suggest the following API:

      <Skeleton isLoaded={!isLoading} skeletonW="150px" skeletonH="21px">
        <Heading as="h3" fontSize="18px">
          {company?.name}
        </Heading>
      </Skeleton>

↩️ Alternatives

I’ve already describe some alternatives, but for now that is the best one (IMHO):

      <Skeleton isLoaded={!isLoading} minW={ isLoading ? '150px' : 'auto' } minH={ isLoading ? '21px' : 'auto' }>
        <Heading as="h3" fontSize="18px">
          {company?.name}
        </Heading>
      </Skeleton>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
stale[bot]commented, Feb 6, 2021

Hi! This issue hasn’t seen any activity recently. We close inactive issues after 35 days to manage the volume of issues we receive. If we missed this issue or you want to keep it open, please reply here. That will reset the timer and allow more time for this issue to be addressed before it is closed.

0reactions
omattmancommented, Sep 27, 2022

+1 would want this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Height not working on body with skeleton - Stack Overflow
The problem is that I cannot set "height" to 100%. I want my footer to be always on the bottom so the rest...
Read more >
Material UI in React #9 - Loading Skeleton - YouTube
Hello fellow react devs! I am happy to share part number nine of the series. In today's episode you will learn how to...
Read more >
Implementing Skeleton Screens In React - Smashing Magazine
Here, height connotes the length of a skeleton rectangle, and width refers to the breadth, while circle creates the rounded part of the...
Read more >
How to Build a Skeleton Screen with CSS for Better UX
A skeleton screen is an animated placeholder that simulates the layout of a website while data is being loaded. They let the user...
Read more >
How to Create a Skeleton Screen Loading Effect in HTML ...
Create a new file index.html ; Note ; Apply the basic CSS attributes like margin ; To add a loading effect, add an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found