-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Support for active state variant #379
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
Conversation
I've updated the pull request because I've realized that some precedences are into play when the output of the state variants takes place. Ups |
@@ -27,7 +28,7 @@ | |||
@component('_partials.customized-config', ['key' => 'modules']) | |||
// ... | |||
- {{ $utility['property'] }}: [{{$currentVariants}}], | |||
+ {{ $utility['property'] }}: ['responsive', 'hover', 'focus'], | |||
+ {{ $utility['property'] }}: ['responsive', 'hover', 'active', 'focus'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could leave this change out I think, otherwise it could become very bloated over time...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you are right
@@ -1,10 +1,10 @@ | |||
--- | |||
extends: _layouts.documentation | |||
title: "State Variants" | |||
description: "Using utilities to style elements on hover, focus, and more." | |||
description: "Using utilities to style elements on hover, active, focus, and more." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
--- | ||
|
||
Similar to our [responsive prefixes](/docs/responsive-design), Tailwind makes it easy to style elements on hover, focus, and more using *state* prefixes. | ||
Similar to our [responsive prefixes](/docs/responsive-design), Tailwind makes it easy to style elements on hover, active, focus, and more using *state* prefixes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
I've updated as you suggested, @MichaelDeBoey. |
Hey thanks for the PR! I'd like to merge this but I disagree with the priority order here; it should be:
...in lowest to highest precedence, IMO. Imagine a button that is focused but not hovered. If I hover it, I expect to see the hover styles, not the focus styles, and if I press it, I expect to see the active styles, not the hover styles: Here's how that same interaction looks using the precedence order that's currently in the PR: The background color never changes after it's been focused, which isn't how I'd expect it to work personally. Happy to merge after that tweak though, thanks! EDIT: Here's a fiddle to test out what I mean, hopefully is convincing: |
Yeah. Makes sense. I was thinking more about text inputs rather than buttons when I decided the order. I asked many persons what colour were they expecting to see when hovering a focused text field, and they all agreed with the current version. (Here is a fork of your fiddle to demonstrate what I mean: https://jsfiddle.net/fedeTibaldo/gzj151dm/ ) However, since inputs still look reasonably good with your desired behaviour whilst buttons do not look OK at all with the current one, I will be happy to update it! |
Yeah that's an annoying problem actually :/ Sucks that we have to pick one way or the other in that case. I think the change I suggested is probably still an improvement since I suspect people are adding hover states to buttons more often than to form controls but it's still a bummer. |
I suspect it too. Here is the updated version! |
Gonna give my unsolicited opinion - landed on this PR just now as I was wondering about the active state. Although initially seeing @adamwathan's GIF had me convinced, I believe after seeing @fedetibaldo's latest fiddle, in the effort of comprise he might have had it best (Current Behavior). Adam, your GIF example does make a bit more sense in the edge-case where someone might focus on a button before hover or clicking, but that case seems slim (I could be wrong, but I think either your predominately using the keyboard, or mouse, but typically not both for a single UI interaction like clicking a button). I can still see customizing text input states as a common task, and clicking on the Desired Behavior text input in that latest fiddle & seeing it behave like a button is a pretty bad experience. I definitely would love to see one way or another merged in soon, but get some more feedback if you guys can. https://jsfiddle.net/fedeTibaldo/gzj151dm/ seems like a solid test. |
Yeah I'm still not fully convinced which behavior I think is better, but in the latest version of Tailwind hover already takes precedence over focus, so changing that would be a breaking change (which is fine) but because of that I think it probably makes sense to merge this PR first in a non-breaking way, and then consider that breaking change separately.
I agree but in reality why would you add The other thing to consider is that I don't think it's super common to style the same property on both focus and hover; usually you would change a border or add an outline on focus, and change the background on hover, so maybe this isn't as big of a deal anyways (although I'd still like to get it as "right" as possible.) It's probably most common to change background on both hover and focus on an input element, so maybe that is the right case to optimize for (although I still think active should always be last). Going to do some research across other sites and see if I can be convinced one way or the other. |
It seems like both approaches have their pros and cons. However, when updating the right properties, the so-called current behaviours is actually better. Why? Let's lay down some hypothesis:
Here is a fiddle: https://jsfiddle.net/fedeTibaldo/6rnbuk5p/ In this real-life scenario, the only visible difference between the two versions is the colour of the input when hovered while focused. At this point, given the fact that all the people I asked to told me that they would feel as more natural if the colour of the input stayed darker when hovered on focus (as stated in one of my previous comments), the current behaviour wins. |
Yep like I mentioned in my previous comment I think it's better to optimize for the input situation than for the button situation, if only because I literally can't find a single example on the entire internet of a site that uses different background colors on a button for focus and hover states; every single example I found where the background color changed on focus used the same color on hover. That said I'm still going to merge this with the order it's in now, and then can change the order in the next breaking release. Holding off merging right this second because our docs site uses the master branch, and I don't want the docs site to be showing features that aren't in a tagged release yet, so I need to update the site to deploy from the most recent tag instead of master before I merge this. |
I'd like to include this in 0.5, feel like rebasing this there and deleting all the docs stuff (since the docs are now in a separate repo)? I can totally do it myself if not, just wanted to give you a chance to get credit for the PR. 0.5 changes the state order to be |
Fixed the conflicts and merged, thanks. |
Here is everything you need to know about this update. Please take a good look at what changed and the test results before merging this pull request. ### What changed? #### ✳️ jiti (2.4.2 → 2.5.1) · [Repo](https://github.com/unjs/jiti) · [Changelog](https://github.com/unjs/jiti/blob/main/CHANGELOG.md) <details> <summary>Release Notes</summary> <h4><a href="https://github.com/unjs/jiti/releases/tag/v2.5.1">2.5.1</a></h4> <blockquote><p dir="auto"><a href="https://bounce.depfu.com/github.com/unjs/jiti/compare/v2.5.0...v2.5.1">compare changes</a></p> <h3 dir="auto">🩹 Fixes</h3> <ul dir="auto"> <li> <strong>interop:</strong> Passthrough module if it is a promise (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/389">#389</a>)</li> </ul></blockquote> <h4><a href="https://github.com/unjs/jiti/releases/tag/v2.5.0">2.5.0</a></h4> <blockquote><p dir="auto"><a href="https://bounce.depfu.com/github.com/unjs/jiti/compare/v2.4.2...v2.5.0">compare changes</a></p> <h3 dir="auto">🚀 Enhancements</h3> <ul dir="auto"> <li>Use <code class="notranslate">sha256</code> for cache entries in FIPS mode (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/375">#375</a>)</li> <li>Support <code class="notranslate">rebuildFsCache</code> ( <code class="notranslate">JITI_REBUILD_FS_CACHE</code>) (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/379">#379</a>)</li> </ul> <h3 dir="auto">🩹 Fixes</h3> <ul dir="auto"> <li>Interop modules with null/undefined default export (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/377">#377</a>)</li> <li>Handle <code class="notranslate">require(<json>)</code> in register mode (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/374">#374</a>)</li> </ul> <h3 dir="auto">📦 Dependencies</h3> <ul dir="auto"> <li>Updated bundled dependencies (<a href="https://bounce.depfu.com/github.com/unjs/jiti/compare/v2.4.2...v2.5.0">compare changes</a>)</li> </ul> <h3 dir="auto">📖 Docs</h3> <ul dir="auto"> <li>Add defaults in JSDocs (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/365">#365</a>)</li> </ul> <h3 dir="auto">✅ Tests</h3> <ul dir="auto"> <li>Only include src for coverage report (<a href="https://bounce.depfu.com/github.com/unjs/jiti/pull/372">#372</a>)</li> </ul> <h3 dir="auto">❤️ Contributors</h3> <ul dir="auto"> <li>Kricsleo (<a href="https://bounce.depfu.com/github.com/kricsleo">@kricsleo</a>) 🌟</li> <li>Pooya Parsa (<a href="https://bounce.depfu.com/github.com/pi0">@pi0</a>)</li> <li>Kanon (<a href="https://bounce.depfu.com/github.com/ysknsid25">@ysknsid25</a>)</li> <li>Arya Emami (<a href="https://bounce.depfu.com/github.com/aryaemami59">@aryaemami59</a>)</li> </ul></blockquote> <p><em>Does any of this look wrong? <a href="https://depfu.com/packages/npm/jiti/feedback">Please let us know.</a></em></p> </details> <details> <summary>Commits</summary> <p><a href="https://github.com/unjs/jiti/compare/340e2a733c35df66c85667ef254eab672f5de210...61fa80358bc71708daf104c1205315d8e5867e4b">See the full diff on Github</a>. The new version differs by 17 commits:</p> <ul> <li><a href="https://github.com/unjs/jiti/commit/61fa80358bc71708daf104c1205315d8e5867e4b"><code>chore(release): v2.5.1</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/ad268df55b9d5df4d365b3bf5c9607b4e12dd34a"><code>fix(interop): passthrough module if it is a promise (#389)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/62eac09b1566e05b87039b5954b344c50fe9da36"><code>chore(release): v2.5.0</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/54461d60611c55074a1f799f99224e24f557eb84"><code>fix(register): handle `require(<json>)` (#374)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/ea2340d1d092c72daec57c48f0fb98ec93ab2bdd"><code>fix: interop modules with nil default export (#377)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/2e5a282f4c67a2fd2050d849e7f844d5e4c9bb21"><code>feat: `rebuildFsCache` ( `JITI_REBUILD_FS_CACHE`) (#379)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/63e907fe3545afe1d376ecce80e5f49f387e1821"><code>feat: use `sha256` for cache entries in fips mode (#375)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/c567a37af6ccdcd18389ddf1ac121bfdc2aa2149"><code>chore: update snapshot</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/fb2da1965405e9c52750726761f6b2bfa36ff3ae"><code>test: only include src for coverage report (#372)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/c9fb9fc0206a2cd7fcc8eaf91328f8d9dd3f3c8f"><code>chore(deps): update autofix-ci/action digest to 635ffb0 (#385)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/dde7c823fae4213ecfb3e35b70a02c05e166ce81"><code>chore: lint</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/35a6a618609f967df3e5e05b295efa462f291206"><code>chore: update deps</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/b396aec45847a32677417ea9dfc78098b6d45c23"><code>chore: add defaults in JSDocs (#365)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/aa541a64ae86b41fb4a17fdba26a2cebb6395d4d"><code>chore(deps): update autofix-ci/action digest to 551dded (#358)</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/fb2b903cc2673652a1bccf6c9b7b9c520c9bf165"><code>chore: update deps</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/c7cfeedbd2326976857bcd62726d73401d25dc03"><code>test: update snapshot</code></a></li> <li><a href="https://github.com/unjs/jiti/commit/6b7fe8b7e6f60f60c26837fadd6288ce2e047b5d"><code>chore: update ci</code></a></li> </ul> </details> ---  [Depfu](https://depfu.com) will automatically keep this PR conflict-free, as long as you don't add any commits to this branch yourself. You can also trigger a rebase manually by commenting with `@depfu rebase`. <details><summary>All Depfu comment commands</summary> <blockquote><dl> <dt>@depfu rebase</dt><dd>Rebases against your default branch and redoes this update</dd> <dt>@depfu recreate</dt><dd>Recreates this PR, overwriting any edits that you've made to it</dd> <dt>@depfu merge</dt><dd>Merges this PR once your tests are passing and conflicts are resolved</dd> <dt>@depfu cancel merge</dt><dd>Cancels automatic merging of this PR</dd> <dt>@depfu close</dt><dd>Closes this PR and deletes the branch</dd> <dt>@depfu reopen</dt><dd>Restores the branch and reopens this PR (if it's closed)</dd> <dt>@depfu pause</dt><dd>Ignores all future updates for this dependency and closes this PR</dd> <dt>@depfu pause [minor|major]</dt><dd>Ignores all future minor/major updates for this dependency and closes this PR</dd> <dt>@depfu resume</dt><dd>Future versions of this dependency will create PRs again (leaves this PR as is)</dd> </dl></blockquote> </details> Co-authored-by: depfu[bot] <23717796+depfu[bot]@users.noreply.github.com>
This is just a small addition to the state variant family.
active
state can come in handy while defining how buttons should behave when clicked, and I guess in a lot of other situations.The thing is: we already support
hover
andfocus
, right? Why notactive
?This pull request includes basic support, documentation and ad-hoc tests. It only needs to get merged to be up and running.
A little sidenote: I changed the order in which state variants get generated, and their tests accordingly (now
hover
gets outputted beforefocus
, andactive
sits between the two). That's to keep the same order throughout the codebase.