tailwindcss/src
Philipp Spiess 680c55c11c
Normalize attribute selector for data-* and aria-* modifiers (#14037)
Fixes #14026 
See #14040 for the v4 fix

When translating `data-` and `aria-` modifiers with attribute selectors,
we currently do not wrap the target attribute in quotes. This only works
for keywords (purely alphabetic words) but breaks as soon as there are
numbers or things like spaces in the attribute:

```html
<div data-id="foo" class="data-[id=foo]:underline">underlined</div>
<div data-id="f1" class="data-[id=1]:underline">not underlined</div>
<div data-id="foo bar" class="data-[id=foo_bar]:underline">not underlined</div>
```

Since it's fairly common to have attribute selectors with `data-` and
`aria-` modifiers, this PR will now wrap the attribute in quotes unless
these are already wrapped.

| Tailwind Modifier  | CSS Selector |
| ------------- | ------------- |
| `.data-[id=foo]`  | `[data-id='foo']`  |
| `.data-[id='foo']`  | `[data-id='foo']`  |
| `.data-[id=foo_i]`  | `[data-id='foo i']`  |
| `.data-[id='foo'_i]`  | `[data-id='foo' i]`  |
| `.data-[id=123]`  | `[data-id='123']`  |

---------

Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
2024-07-24 18:46:21 +02:00
..
cli Cleanup oxide — Part #2 (#13312) 2024-03-22 17:12:14 +01:00
css Reset letter spacing for form elements (#13150) 2024-03-22 14:49:22 -04:00
lib Fix class detection in Slim templates with attached attributes and IDs (#14019) 2024-07-18 11:21:20 -04:00
postcss-plugins/nesting Redirect to the up-to-date plugin url (#8081) 2022-04-11 13:06:10 -04:00
public Extend default color palette with new 950 shades (#10879) 2023-03-27 14:47:13 -04:00
util Normalize attribute selector for data-* and aria-* modifiers (#14037) 2024-07-24 18:46:21 +02:00
value-parser Fix parsing of theme() inside calc() when there are no spaces around operators (#11157) 2023-07-13 11:48:34 -04:00
cli-peer-dependencies.js Add postcss-import support to the CLI (#8437) 2022-05-25 14:28:52 -04:00
cli.js Cleanup oxide — Part #2 (#13312) 2024-03-22 17:12:14 +01:00
corePlugins.js Normalize attribute selector for data-* and aria-* modifiers (#14037) 2024-07-24 18:46:21 +02:00
featureFlags.js Cleanup oxide — Part #2 (#13312) 2024-03-22 17:12:14 +01:00
index.js Replace __OXIDE__ at build time to prevent @tailwindcss/oxide leaks in the stable engine (#10988) 2023-04-18 12:19:20 +02:00
plugin.js Cleanup oxide — Part #2 (#13312) 2024-03-22 17:12:14 +01:00
processTailwindFeatures.js Only detect nesting when using @apply (#13325) 2024-03-23 19:10:51 -04:00