Skip to content

Commit 7df3d93

Browse files
Correctly parse and prefix animation names with dots (#7163)
* Add prefix alone to animation names. Fixes #7149. * Add test for keyframe animations with a dot in the name * Add test for prefixed version * Fix CS * Simplify * Update changelog * Fix Co-authored-by: Jordan Pittman <[email protected]>
1 parent 10103d8 commit 7df3d93

File tree

3 files changed

+97
-2
lines changed

3 files changed

+97
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Use local user CSS cache for `@apply` ([#7524](https://github.com/tailwindlabs/tailwindcss/pull/7524))
1717
- Invalidate context when main CSS changes ([#7626](https://github.com/tailwindlabs/tailwindcss/pull/7626))
1818
- Only add `!` to selector class matching template candidate when using important modifier with mutli-class selectors ([#7664](https://github.com/tailwindlabs/tailwindcss/pull/7664))
19+
- Correctly parse and prefix animation names with dots ([#7163](https://github.com/tailwindlabs/tailwindcss/pull/7163))
1920

2021
### Changed
2122

src/corePlugins.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as path from 'path'
33
import postcss from 'postcss'
44
import createUtilityPlugin from './util/createUtilityPlugin'
55
import buildMediaQuery from './util/buildMediaQuery'
6+
import escapeClassName from './util/escapeClassName'
67
import parseAnimationValue from './util/parseAnimationValue'
78
import flattenColorPalette from './util/flattenColorPalette'
89
import withAlphaVariable, { withAlphaValue } from './util/withAlphaVariable'
@@ -612,8 +613,8 @@ export let corePlugins = {
612613
})
613614
},
614615

615-
animation: ({ matchUtilities, theme, prefix }) => {
616-
let prefixName = (name) => prefix(`.${name}`).slice(1)
616+
animation: ({ matchUtilities, theme, config }) => {
617+
let prefixName = (name) => `${config('prefix')}${escapeClassName(name)}`
617618
let keyframes = Object.fromEntries(
618619
Object.entries(theme('keyframes') ?? {}).map(([key, value]) => {
619620
return [key, { [`@keyframes ${prefixName(key)}`]: value }]

tests/animations.test.js

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,96 @@ test('multiple custom', () => {
181181
`)
182182
})
183183
})
184+
185+
test('with dots in the name', () => {
186+
let config = {
187+
content: [
188+
{
189+
raw: html`
190+
<div class="animate-zoom-.5"></div>
191+
<div class="animate-zoom-1.5"></div>
192+
`,
193+
},
194+
],
195+
theme: {
196+
extend: {
197+
keyframes: {
198+
'zoom-.5': { to: { transform: 'scale(0.5)' } },
199+
'zoom-1.5': { to: { transform: 'scale(1.5)' } },
200+
},
201+
animation: {
202+
'zoom-.5': 'zoom-.5 2s',
203+
'zoom-1.5': 'zoom-1.5 2s',
204+
},
205+
},
206+
},
207+
}
208+
209+
return run('@tailwind utilities', config).then((result) => {
210+
expect(result.css).toMatchFormattedCss(css`
211+
@keyframes zoom-\.5 {
212+
to {
213+
transform: scale(0.5);
214+
}
215+
}
216+
.animate-zoom-\.5 {
217+
animation: zoom-\.5 2s;
218+
}
219+
@keyframes zoom-1\.5 {
220+
to {
221+
transform: scale(1.5);
222+
}
223+
}
224+
.animate-zoom-1\.5 {
225+
animation: zoom-1\.5 2s;
226+
}
227+
`)
228+
})
229+
})
230+
231+
test('with dots in the name and prefix', () => {
232+
let config = {
233+
prefix: 'tw-',
234+
content: [
235+
{
236+
raw: html`
237+
<div class="tw-animate-zoom-.5"></div>
238+
<div class="tw-animate-zoom-1.5"></div>
239+
`,
240+
},
241+
],
242+
theme: {
243+
extend: {
244+
keyframes: {
245+
'zoom-.5': { to: { transform: 'scale(0.5)' } },
246+
'zoom-1.5': { to: { transform: 'scale(1.5)' } },
247+
},
248+
animation: {
249+
'zoom-.5': 'zoom-.5 2s',
250+
'zoom-1.5': 'zoom-1.5 2s',
251+
},
252+
},
253+
},
254+
}
255+
256+
return run('@tailwind utilities', config).then((result) => {
257+
expect(result.css).toMatchFormattedCss(css`
258+
@keyframes tw-zoom-\.5 {
259+
to {
260+
transform: scale(0.5);
261+
}
262+
}
263+
.tw-animate-zoom-\.5 {
264+
animation: tw-zoom-\.5 2s;
265+
}
266+
@keyframes tw-zoom-1\.5 {
267+
to {
268+
transform: scale(1.5);
269+
}
270+
}
271+
.tw-animate-zoom-1\.5 {
272+
animation: tw-zoom-1\.5 2s;
273+
}
274+
`)
275+
})
276+
})

0 commit comments

Comments
 (0)