Skip to content

Commit 948fcf5

Browse files
committed
fix(placeholder): fix placeholder on focus
It was not generating placeholder pseudo elements when focus was also applied
1 parent 5987cdf commit 948fcf5

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

__tests__/index.test.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,36 @@ describe('plugin', () => {
237237
.text-gray-100 {
238238
color: #333333
239239
}
240-
.theme-dark .dark\\:focus\\:text-gray-100:focus {
240+
.theme-dark .dark\\:focus\\:text-gray-100\\:focus {
241+
color: #333333
242+
}
243+
`)
244+
})
245+
})
246+
247+
it('should generate :focus placeholder variants', () => {
248+
return generatePluginCss({
249+
...baseTestTheme,
250+
variants: {
251+
textColor: ['dark:focus'],
252+
placeholderColor: ['focus', 'dark:focus'],
253+
},
254+
corePlugins: ['textColor', 'placeholderColor'],
255+
}).then((css) => {
256+
expect(css).toMatchCss(`
257+
.text-gray-100 {
258+
color: #333333
259+
}
260+
.theme-dark .dark\\:focus\\:text-gray-100\\:focus {
261+
color: #333333
262+
}
263+
.placeholder-gray-100::placeholder {
264+
color: #333333
265+
}
266+
.focus\\:placeholder-gray-100:focus::placeholder {
267+
color: #333333
268+
}
269+
.theme-dark .dark\\:focus\\:placeholder-gray-100\\:focus::placeholder {
241270
color: #333333
242271
}
243272
`)

src/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,13 @@ module.exports = ({ addVariant, theme, e }) => {
7979
})
8080

8181
addVariant(`${tv}:focus`, ({ modifySelectors, separator }) => {
82-
modifySelectors(({ className }) => {
83-
return `${root}.${e(`${tv}${separator}focus${separator}${className}`)}:focus`
82+
modifySelectors(({ selector }) => {
83+
return selectorParser((selectors) => {
84+
selectors.walkClasses((sel) => {
85+
sel.value = `${tv}${separator}focus${separator}${sel.value}:focus`
86+
sel.parent.insertBefore(sel, selectorParser().astSync(root))
87+
})
88+
}).processSync(selector)
8489
})
8590
})
8691

0 commit comments

Comments
 (0)