Skip to content

Commit 488f913

Browse files
authored
Merge pull request #451 from dcastil/bugfix/448/fix-bg-opacity-arbitrary-percentage-not-working
Fix bg-opacity arbitrary percentages not being recognized properly
2 parents f3b5d4a + 90e2b01 commit 488f913

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/lib/default-config.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export const getDefaultConfig = () => {
8686
const getZeroAndEmpty = () => ['', '0', isArbitraryValue] as const
8787
const getBreaks = () =>
8888
['auto', 'avoid', 'all', 'avoid-page', 'page', 'left', 'right', 'column'] as const
89-
const getNumber = () => [isNumber, isArbitraryNumber]
9089
const getNumberAndArbitrary = () => [isNumber, isArbitraryValue]
9190

9291
return {
@@ -96,12 +95,12 @@ export const getDefaultConfig = () => {
9695
colors: [isAny],
9796
spacing: [isLength, isArbitraryLength],
9897
blur: ['none', '', isTshirtSize, isArbitraryValue],
99-
brightness: getNumber(),
98+
brightness: getNumberAndArbitrary(),
10099
borderColor: [colors],
101100
borderRadius: ['none', '', 'full', isTshirtSize, isArbitraryValue],
102101
borderSpacing: getSpacingWithArbitrary(),
103102
borderWidth: getLengthWithEmptyAndArbitrary(),
104-
contrast: getNumber(),
103+
contrast: getNumberAndArbitrary(),
105104
grayscale: getZeroAndEmpty(),
106105
hueRotate: getNumberAndArbitrary(),
107106
invert: getZeroAndEmpty(),
@@ -110,10 +109,10 @@ export const getDefaultConfig = () => {
110109
gradientColorStopPositions: [isPercent, isArbitraryLength],
111110
inset: getSpacingWithAutoAndArbitrary(),
112111
margin: getSpacingWithAutoAndArbitrary(),
113-
opacity: getNumber(),
112+
opacity: getNumberAndArbitrary(),
114113
padding: getSpacingWithArbitrary(),
115-
saturate: getNumber(),
116-
scale: getNumber(),
114+
saturate: getNumberAndArbitrary(),
115+
scale: getNumberAndArbitrary(),
117116
sepia: getZeroAndEmpty(),
118117
skew: getNumberAndArbitrary(),
119118
space: getSpacingWithArbitrary(),

tests/arbitrary-properties.test.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ test('handles arbitrary property conflicts with modifiers correctly', () => {
2020
expect(
2121
twMerge('[paint-order:markers] [paint-order:normal] [--my-var:2rem] lg:[--my-var:4px]'),
2222
).toBe('[paint-order:normal] [--my-var:2rem] lg:[--my-var:4px]')
23+
expect(twMerge('bg-[#B91C1C] bg-opacity-[0.56] bg-opacity-[48%]')).toBe(
24+
'bg-[#B91C1C] bg-opacity-[48%]',
25+
)
2326
})
2427

2528
test('handles complex arbitrary property conflicts correctly', () => {

0 commit comments

Comments
 (0)