Skip to content

Commit a7263a8

Browse files
mwnciauSimon Jarrett
andauthored
Add support for negative values in safelist patterns (#6480)
Co-authored-by: Simon Jarrett <[email protected]>
1 parent 5079b9c commit a7263a8

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Don't output unparsable values ([#6469](https://github.com/tailwindlabs/tailwindcss/pull/6469))
1818
- Fix text decoration utilities from overriding the new text decoration color/style/thickness utilities when used with a modifier ([#6378](https://github.com/tailwindlabs/tailwindcss/pull/6378))
1919
- Move defaults to their own always-on layer ([#6500](https://github.com/tailwindlabs/tailwindcss/pull/6500))
20+
- Support negative values in safelist patterns ([6480](https://github.com/tailwindlabs/tailwindcss/pull/6480))
2021

2122
## [3.0.2] - 2021-12-13
2223

src/lib/setupContextUtils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,15 @@ function registerPlugins(plugins, context) {
651651
let utils = Array.isArray(util)
652652
? (() => {
653653
let [utilName, options] = util
654-
return Object.keys(options?.values ?? {}).map((value) => formatClass(utilName, value))
654+
let classes = Object.keys(options?.values ?? {}).map((value) =>
655+
formatClass(utilName, value)
656+
)
657+
658+
if (options?.supportsNegativeValues) {
659+
classes = [...classes, ...classes.map((cls) => '-' + cls)]
660+
}
661+
662+
return classes
655663
})()
656664
: [util]
657665

tests/safelist.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,31 @@ it('should not safelist when an sparse/holey list is provided', () => {
194194
`)
195195
})
196196
})
197+
198+
it('should safelist negatives based on a pattern regex', () => {
199+
let config = {
200+
content: [{ raw: html`<div class="uppercase"></div>` }],
201+
safelist: [
202+
{
203+
pattern: /^-top-1$/,
204+
variants: ['hover'],
205+
},
206+
],
207+
}
208+
209+
return run('@tailwind utilities', config).then((result) => {
210+
return expect(result.css).toMatchCss(css`
211+
.-top-1 {
212+
top: -0.25rem;
213+
}
214+
215+
.uppercase {
216+
text-transform: uppercase;
217+
}
218+
219+
.hover\:-top-1:hover {
220+
top: -0.25rem;
221+
}
222+
`)
223+
})
224+
})

0 commit comments

Comments
 (0)