Skip to content

Ensure nested selectors using &:hover work #246

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

Merged
merged 2 commits into from
Feb 14, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Ensure nested selectors using `&:hover` work ([#246](https://github.com/tailwindlabs/tailwindcss-typography/pull/246))

## [0.5.1] - 2022-01-28

### Removed
Expand Down
12 changes: 4 additions & 8 deletions jest/customMatchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ expect.extend({
return { actual: received, message, pass }
},
toIncludeCss(received, argument) {
function stripped(str) {
return str.replace(/\s/g, '').replace(/;/g, '')
}

const options = {
comment: 'stripped(received).includes(stripped(argument))',
isNot: this.isNot,
promise: this.promise,
}

const pass = stripped(received).includes(stripped(argument))
const actual = format(received)
const expected = format(argument)

const pass = actual.includes(expected)

const message = pass
? () => {
Expand All @@ -76,9 +75,6 @@ expect.extend({
)
}
: () => {
const actual = format(received)
const expected = format(argument)

const diffString = diff(expected, actual, {
expand: this.expand,
})
Expand Down
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ function configToCss(config = {}, { target, className, prefix }) {
if (isObject(v)) {
let nested = Object.values(v).some(isObject)
if (nested) {
return [k, Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v)))]
return [
inWhere(k, { className, prefix }),
v,
Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v))),
]
}

return [inWhere(k, { className, prefix }), v]
Expand Down
52 changes: 51 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const typographyPlugin = require('.')

let html = String.raw
let css = String.raw
let javascript = String.raw

function run(config, plugin = tailwind) {
let { currentTestName } = expect.getState()
Expand Down Expand Up @@ -831,3 +830,54 @@ test('customizing defaults with multiple values does not result in invalid css',
`)
})
})

it('should be possible to use nested syntax (&) when extending the config', () => {
let config = {
plugins: [typographyPlugin()],
content: [
{
raw: html`<div class="prose"></div>`,
},
],
theme: {
extend: {
typography: {
DEFAULT: {
css: {
color: '#000',
a: {
color: '#888',
'&:hover': {
color: '#ff0000',
},
},
},
},
},
},
},
}

return run(config).then((result) => {
expect(result.css).toIncludeCss(css`
.prose {
color: #000;
max-width: 65ch;
}
`)

expect(result.css).toIncludeCss(css`
.prose :where(a):not(:where([class~='not-prose'] *)) {
color: #888;
text-decoration: underline;
font-weight: 500;
}
`)

expect(result.css).toIncludeCss(css`
.prose :where(a):not(:where([class~='not-prose'] *)):hover {
color: #ff0000;
}
`)
})
})