Skip to content
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

Normalize attribute selector for data-* and aria-* modifiers #14037

Merged
merged 5 commits into from
Jul 24, 2024

Conversation

philipp-spiess
Copy link
Contributor

@philipp-spiess philipp-spiess commented Jul 23, 2024

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:

<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']

@thecrypticace
Copy link
Contributor

thecrypticace commented Jul 23, 2024

fyi this is technically breaking. Though in practice it may not actually matter. I kinda doubt people are using this feature but today this candidate causes the div to be underlined:

<div class="data-[id=foo_i]:underline" data-id="fOO">test</div>

However, after this PR it won't. I think it's probably okay to ship as-is but we'll want to at least make note of this in case we need to follow it up with a fix (and check for I and s)

@philipp-spiess
Copy link
Contributor Author

@thecrypticace Hmm yes indeed. As you say, it's easy to catch this case and check for the valid flags if we want to. Let's for sure make a not though!

@RobinMalfait RobinMalfait changed the title Normalize attribute selector for data- and aria- modifiers Normalize attribute selector for data-* and aria-* modifiers Jul 23, 2024
CHANGELOG.md Outdated Show resolved Hide resolved
philipp-spiess and others added 2 commits July 24, 2024 09:35
Co-authored-by: Robin Malfait <malfait.robin@gmail.com>
philipp-spiess added a commit that referenced this pull request Jul 24, 2024
…4040)

Fixes #14026 
See #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>
@philipp-spiess philipp-spiess merged commit 680c55c into master Jul 24, 2024
13 checks passed
@philipp-spiess philipp-spiess deleted the fix/issue-14026 branch July 24, 2024 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants