tailwindcss/packages
Philipp Spiess 300524b893
Normalize attribute selectors for data-* and aria-* modifiers (#14040)
Fixes #14026 
See https://github.com/tailwindlabs/tailwindcss/pull/14037 for the v3
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 16:55:07 +02:00
..
@tailwindcss-cli Add support for basic addVariant plugins with new @plugin directive (#13982) 2024-07-11 09:47:26 -04:00
@tailwindcss-postcss Add support for basic addVariant plugins with new @plugin directive (#13982) 2024-07-11 09:47:26 -04:00
@tailwindcss-vite Add support for basic addVariant plugins with new @plugin directive (#13982) 2024-07-11 09:47:26 -04:00
tailwindcss Normalize attribute selectors for data-* and aria-* modifiers (#14040) 2024-07-24 16:55:07 +02:00
test-utils Add support for basic addVariant plugins with new @plugin directive (#13982) 2024-07-11 09:47:26 -04:00
tsconfig.base.json introduce v4 codebase 2024-03-05 14:29:15 +01:00