Skip to content

Commit a9b4266

Browse files
authored
Ensure nested selectors using &:hover work (#246)
* ensure nested selectors using `&:hover` work * update changelog
1 parent d044408 commit a9b4266

File tree

4 files changed

+64
-10
lines changed

4 files changed

+64
-10
lines changed

Diff for: CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Ensure nested selectors using `&:hover` work ([#246](https://github.com/tailwindlabs/tailwindcss-typography/pull/246))
13+
1014
## [0.5.1] - 2022-01-28
1115

1216
### Removed

Diff for: jest/customMatchers.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,16 @@ expect.extend({
5454
return { actual: received, message, pass }
5555
},
5656
toIncludeCss(received, argument) {
57-
function stripped(str) {
58-
return str.replace(/\s/g, '').replace(/;/g, '')
59-
}
60-
6157
const options = {
6258
comment: 'stripped(received).includes(stripped(argument))',
6359
isNot: this.isNot,
6460
promise: this.promise,
6561
}
6662

67-
const pass = stripped(received).includes(stripped(argument))
63+
const actual = format(received)
64+
const expected = format(argument)
65+
66+
const pass = actual.includes(expected)
6867

6968
const message = pass
7069
? () => {
@@ -76,9 +75,6 @@ expect.extend({
7675
)
7776
}
7877
: () => {
79-
const actual = format(received)
80-
const expected = format(argument)
81-
8278
const diffString = diff(expected, actual, {
8379
expand: this.expand,
8480
})

Diff for: src/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ function configToCss(config = {}, { target, className, prefix }) {
5656
if (isObject(v)) {
5757
let nested = Object.values(v).some(isObject)
5858
if (nested) {
59-
return [k, Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v)))]
59+
return [
60+
inWhere(k, { className, prefix }),
61+
v,
62+
Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v))),
63+
]
6064
}
6165

6266
return [inWhere(k, { className, prefix }), v]

Diff for: src/index.test.js

+51-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const typographyPlugin = require('.')
55

66
let html = String.raw
77
let css = String.raw
8-
let javascript = String.raw
98

109
function run(config, plugin = tailwind) {
1110
let { currentTestName } = expect.getState()
@@ -831,3 +830,54 @@ test('customizing defaults with multiple values does not result in invalid css',
831830
`)
832831
})
833832
})
833+
834+
it('should be possible to use nested syntax (&) when extending the config', () => {
835+
let config = {
836+
plugins: [typographyPlugin()],
837+
content: [
838+
{
839+
raw: html`<div class="prose"></div>`,
840+
},
841+
],
842+
theme: {
843+
extend: {
844+
typography: {
845+
DEFAULT: {
846+
css: {
847+
color: '#000',
848+
a: {
849+
color: '#888',
850+
'&:hover': {
851+
color: '#ff0000',
852+
},
853+
},
854+
},
855+
},
856+
},
857+
},
858+
},
859+
}
860+
861+
return run(config).then((result) => {
862+
expect(result.css).toIncludeCss(css`
863+
.prose {
864+
color: #000;
865+
max-width: 65ch;
866+
}
867+
`)
868+
869+
expect(result.css).toIncludeCss(css`
870+
.prose :where(a):not(:where([class~='not-prose'] *)) {
871+
color: #888;
872+
text-decoration: underline;
873+
font-weight: 500;
874+
}
875+
`)
876+
877+
expect(result.css).toIncludeCss(css`
878+
.prose :where(a):not(:where([class~='not-prose'] *)):hover {
879+
color: #ff0000;
880+
}
881+
`)
882+
})
883+
})

0 commit comments

Comments
 (0)