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

Only prefix animation names that are defined #2641

Merged
merged 1 commit into from Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 41 additions & 2 deletions __tests__/plugins/animation.test.js
Expand Up @@ -80,13 +80,52 @@ test('defining animation and keyframes with prefix', () => {
}
}
}

@layer utilities {
@variants {
.tw-animate-none { animation: none; }
.tw-animate-spin { animation: tw-spin 1s linear infinite; }
.tw-animate-ping { animation: tw-ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; }
}
}
}
`)
})

test('defining animation and keyframes with prefix (skip undefined animations)', () => {
const config = {
prefix: 'tw-',
theme: {
animation: {
none: 'none',
spin: 'spin 1s linear infinite',
ping: 'ping 1s cubic-bezier(0, 0, 0.2, 1) infinite',
},
keyframes: {
spin: { to: { transform: 'rotate(360deg)' } },
},
},
variants: {
animation: [],
},
}

const { utilities } = processPlugins([plugin()], config)

expect(css(utilities)).toMatchCss(`
@layer utilities {
@variants {
@keyframes tw-spin {
to { transform: rotate(360deg); }
}
}
}

@layer utilities {
@variants {
.tw-animate-none { animation: none; }
.tw-animate-spin { animation: tw-spin 1s linear infinite; }
.tw-animate-ping { animation: ping 1s cubic-bezier(0, 0, 0.2, 1) infinite; }
}
}
`)
})
2 changes: 1 addition & 1 deletion src/plugins/animation.js
Expand Up @@ -18,7 +18,7 @@ export default function () {
_.mapKeys(animationConfig, (_animation, suffix) => nameClass('animate', suffix)),
(animation) => {
const { name } = parseAnimationValue(animation)
if (name === undefined) return { animation }
if (name === undefined || keyframesConfig[name] === undefined) return { animation }
return { animation: animation.replace(name, prefixName(name)) }
}
)
Expand Down