Skip to content

Commit 33b589a

Browse files
committed
Fix enableAnimation regression
1 parent f44e607 commit 33b589a

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

src/Skeleton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function styleOptionsToCssProperties({
2323

2424
if (direction === 'rtl') style['--animation-direction'] = 'reverse'
2525
if (typeof duration === 'number') style['--animation-duration'] = `${duration}s`
26-
if (!enableAnimation) style.backgroundImage = 'none'
26+
if (!enableAnimation) style['--pseudo-element-display'] = 'none'
2727

2828
if (typeof width === 'string' || typeof width === 'number') style.width = width
2929
if (typeof height === 'string' || typeof height === 'number') style.height = height

src/__tests__/Skeleton.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ it('adds a line break when inline is false', () => {
7878

7979
it('disables the animation if and only if enableAnimation is false', () => {
8080
const { rerender } = render(<Skeleton containerTestId="container" />)
81-
expect(getSkeleton()).toHaveStyle({ backgroundImage: /linear-gradient/ })
81+
expect(getSkeleton().style.getPropertyValue('--pseudo-element-display')).toBe('')
8282
expect(screen.getByTestId('container')).toHaveAttribute('aria-busy', 'true')
8383

8484
rerender(<Skeleton enableAnimation containerTestId="container" />)
85-
expect(getSkeleton()).toHaveStyle({ backgroundImage: /linear-gradient/ })
85+
expect(getSkeleton().style.getPropertyValue('--pseudo-element-display')).toBe('')
8686
expect(screen.getByTestId('container')).toHaveAttribute('aria-busy', 'true')
8787

8888
rerender(<Skeleton enableAnimation={false} containerTestId="container" />)
89-
expect(getSkeleton()).toHaveStyle({ backgroundImage: 'none' })
89+
expect(getSkeleton().style.getPropertyValue('--pseudo-element-display')).toBe('none')
9090
expect(screen.getByTestId('container')).toHaveAttribute('aria-busy', 'false')
9191
})
9292

src/skeleton.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
--highlight-color: #f5f5f5;
1010
--animation-duration: 1.5s;
1111
--animation-direction: normal;
12+
--pseudo-element-display: block; /* Enable animation */
1213

1314
background-color: var(--base-color);
1415

@@ -24,7 +25,7 @@
2425

2526
.react-loading-skeleton::after {
2627
content: ' ';
27-
display: block;
28+
display: var(--pseudo-element-display);
2829
position: absolute;
2930
left: 0;
3031
right: 0;

0 commit comments

Comments
 (0)