Skip to content

Commit 67ff8ea

Browse files
Limit attribute rules to input and select elements (#159)
Currently the rules for styling the inputs are too broad and may conflict with web components that use props named type or mutiple. This PR address this issue by using :where to select only inputs without change the specificity. --------- Co-authored-by: Jordan Pittman <[email protected]>
1 parent fc3f7e6 commit 67ff8ea

File tree

2 files changed

+32
-30
lines changed

2 files changed

+32
-30
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Limit attribute rules to input and select elements ([#159](https://github.com/tailwindlabs/tailwindcss-forms/pull/159))
1113

1214
## [0.5.10] - 2025-01-07
1315

src/index.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
2626
const rules = [
2727
{
2828
base: [
29-
"[type='text']",
29+
"input:where([type='text'])",
3030
'input:where(:not([type]))',
31-
"[type='email']",
32-
"[type='url']",
33-
"[type='password']",
34-
"[type='number']",
35-
"[type='date']",
36-
"[type='datetime-local']",
37-
"[type='month']",
38-
"[type='search']",
39-
"[type='tel']",
40-
"[type='time']",
41-
"[type='week']",
42-
'[multiple]',
31+
"input:where([type='email'])",
32+
"input:where([type='url'])",
33+
"input:where([type='password'])",
34+
"input:where([type='number'])",
35+
"input:where([type='date'])",
36+
"input:where([type='datetime-local'])",
37+
"input:where([type='month'])",
38+
"input:where([type='search'])",
39+
"input:where([type='tel'])",
40+
"input:where([type='time'])",
41+
"input:where([type='week'])",
42+
'select:where([multiple])',
4343
'textarea',
4444
'select',
4545
],
@@ -176,7 +176,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
176176
},
177177
},
178178
{
179-
base: ['[multiple]', '[size]:where(select:not([size="1"]))'],
179+
base: ['select:where([multiple])', 'select:where([size]:not([size="1"]))'],
180180
class: ['.form-select:where([size]:not([size="1"]))'],
181181
styles: {
182182
'background-image': 'initial',
@@ -188,7 +188,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
188188
},
189189
},
190190
{
191-
base: [`[type='checkbox']`, `[type='radio']`],
191+
base: [`input:where([type='checkbox'])`, `input:where([type='radio'])`],
192192
class: ['.form-checkbox', '.form-radio'],
193193
styles: {
194194
appearance: 'none',
@@ -212,21 +212,21 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
212212
},
213213
},
214214
{
215-
base: [`[type='checkbox']`],
215+
base: [`input:where([type='checkbox'])`],
216216
class: ['.form-checkbox'],
217217
styles: {
218218
'border-radius': borderRadius['none'],
219219
},
220220
},
221221
{
222-
base: [`[type='radio']`],
222+
base: [`input:where([type='radio'])`],
223223
class: ['.form-radio'],
224224
styles: {
225225
'border-radius': '100%',
226226
},
227227
},
228228
{
229-
base: [`[type='checkbox']:focus`, `[type='radio']:focus`],
229+
base: [`input:where([type='checkbox']):focus`, `input:where([type='radio']):focus`],
230230
class: ['.form-checkbox:focus', '.form-radio:focus'],
231231
styles: {
232232
outline: '2px solid transparent',
@@ -244,7 +244,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
244244
},
245245
},
246246
{
247-
base: [`[type='checkbox']:checked`, `[type='radio']:checked`],
247+
base: [`input:where([type='checkbox']):checked`, `input:where([type='radio']):checked`],
248248
class: ['.form-checkbox:checked', '.form-radio:checked'],
249249
styles: {
250250
'border-color': `transparent`,
@@ -255,7 +255,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
255255
},
256256
},
257257
{
258-
base: [`[type='checkbox']:checked`],
258+
base: [`input:where([type='checkbox']):checked`],
259259
class: ['.form-checkbox:checked'],
260260
styles: {
261261
'background-image': `url("${svgToDataUri(
@@ -268,7 +268,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
268268
},
269269
},
270270
{
271-
base: [`[type='radio']:checked`],
271+
base: [`input:where([type='radio']):checked`],
272272
class: ['.form-radio:checked'],
273273
styles: {
274274
'background-image': `url("${svgToDataUri(
@@ -282,10 +282,10 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
282282
},
283283
{
284284
base: [
285-
`[type='checkbox']:checked:hover`,
286-
`[type='checkbox']:checked:focus`,
287-
`[type='radio']:checked:hover`,
288-
`[type='radio']:checked:focus`,
285+
`input:where([type='checkbox']):checked:hover`,
286+
`input:where([type='checkbox']):checked:focus`,
287+
`input:where([type='radio']):checked:hover`,
288+
`input:where([type='radio']):checked:focus`,
289289
],
290290
class: [
291291
'.form-checkbox:checked:hover',
@@ -299,7 +299,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
299299
},
300300
},
301301
{
302-
base: [`[type='checkbox']:indeterminate`],
302+
base: [`input:where([type='checkbox']):indeterminate`],
303303
class: ['.form-checkbox:indeterminate'],
304304
styles: {
305305
'background-image': `url("${svgToDataUri(
@@ -317,15 +317,15 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
317317
},
318318
},
319319
{
320-
base: [`[type='checkbox']:indeterminate:hover`, `[type='checkbox']:indeterminate:focus`],
320+
base: [`input:where([type='checkbox']):indeterminate:hover`, `input:where([type='checkbox']):indeterminate:focus`],
321321
class: ['.form-checkbox:indeterminate:hover', '.form-checkbox:indeterminate:focus'],
322322
styles: {
323323
'border-color': 'transparent',
324324
'background-color': 'currentColor',
325325
},
326326
},
327327
{
328-
base: [`[type='file']`],
328+
base: [`input:where([type='file'])`],
329329
class: null,
330330
styles: {
331331
background: 'unset',
@@ -338,7 +338,7 @@ const forms = plugin.withOptions(function (options = { strategy: undefined }) {
338338
},
339339
},
340340
{
341-
base: [`[type='file']:focus`],
341+
base: [`input:where([type='file']):focus`],
342342
class: null,
343343
styles: {
344344
outline: [`1px solid ButtonText`, `1px auto -webkit-focus-ring-color`],

0 commit comments

Comments
 (0)