-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Clarify status of class:directive #15112
Comments
We haven't done so yet, because For now the docs are focused on encouraging people to use I know some people prefer <nav>
<a href="/" class:active={page.url.pathname === '/'}>home</a>
<a href="/about" class:active={page.url.pathname === '/about'}>about</a>
</nav> ...but it's much better to do this: <nav>
<a href="/" aria-current={page.url.pathname === '/' ? 'page' : undefined}>home</a>
<a href="/about" aria-current={page.url.pathname === '/about' ? 'page' : undefined}>about</a>
</nav> Most of the time, there's an aria attribute or something else (like <button
class="card"
data-flipped={flipped}
onclick={() => flipped = !flipped}
> Essentially, classes are supposed to describe what kind of thing something is. Other attributes describe the state of the thing. Put differently, The exception, of course, is Tailwind (and its imitators), where 'semantic HTML' is sneered at. If you're using Tailwind, you really do need dynamic classes. But the reason we added So if you're using Tailwind, you need |
@Rich-Harris I don't believe semantic HTML and tailwind are mutually exclusive. <nav>
<a class="aria-[current=page]:text-blue-600" href="/" aria-current={page.url.pathname === '/' ? 'page' : undefined}>home</a>
<a class="aria-[current=page]:text-blue-600" href="/about" aria-current={page.url.pathname === '/about' ? 'page' : undefined}>about</a>
</nav> |
You certainly can write Tailwind like that, though I'm not totally sure how common it is. Either way it's another situation in which there's no call for dynamic classes. |
|
Why not explicitly say this in the docs? This is the case for other things in the docs. |
Describe the bug
Currently, the docs on svelte class directive state:
Upon requesting the
cli
maintainers to work on a migration script, the svelte team member said that perhaps the docs is pushing the new syntax a bit too much and may require clarification.As I do not have the data or heuristics to know if and when there is noticeable differences in performance or DevEx, it seems best for a maintainer to edit the docs in one or two sentences to clarify the future of class:directives, performance gains/losses, and whether this is opt-in or the new norm.
A starting point could be
Reproduction
N/A
Logs
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: