Skip to content

Commit 083c05d

Browse files
add Skeleton width guide to README Example (#178)
* add Skeleton width guide in README example * fix: Skeleton width becomes 0 explanation * Update README.md * Improve the README section about `display: flex` parents --------- Co-authored-by: Sam Magura <[email protected]>
1 parent 375f869 commit 083c05d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ return (
109109
<tr>
110110
<td><code>count?: number</code></td>
111111
<td>
112-
The number of lines of skeletons to render. If
112+
The number of lines of skeletons to render. If
113113
<code>count</code> is a decimal number like 3.5,
114114
three full skeletons and one half-width skeleton will be
115115
rendered.
@@ -273,6 +273,29 @@ const wrapped2 = (
273273
);
274274
```
275275

276+
## Troubleshooting
277+
278+
### The skeleton width is 0 when the parent has `display: flex`!
279+
280+
In the example below, the width of the skeleton will be 0:
281+
282+
```tsx
283+
<div style={{ display: 'flex' }}>
284+
<Skeleton />
285+
</div>
286+
```
287+
288+
This happens because the skeleton has no intrinsic width. You can fix it by
289+
applying `flex: 1` to the skeleton container via the `containerClassName` prop.
290+
291+
For example, if you are using Tailwind, your code would look like this:
292+
293+
```tsx
294+
<div style={{ display: 'flex' }}>
295+
<Skeleton containerClassName="flex-1" />
296+
</div>
297+
```
298+
276299
### The height of my container is off by a few pixels!
277300

278301
In the example below, the height of the `<div>` will be slightly larger than 30

0 commit comments

Comments
 (0)