Commit abde4c9
Only apply hover on devices that support hover (#14500)
This PR updates the `hover` variant to only apply when `@media (hover:
hover)` matches.
```diff
.hover\:bg-black {
&:hover {
+ @media (hover: hover) {
background: black;
+ }
}
}
```
This is technically a breaking change because you may have built your
site in a way where some interactions depend on hover (like opening a
dropdown menu), and were relying on the fact that tapping on mobile
triggers hover.
To bring back the old hover behavior, users can override the `hover`
variant in their CSS file back to the simpler implementation:
```css
@import "tailwindcss";
@variant hover (&:hover);
```
I've opted to go with just `@media (hover: hover)` for this because it
seems like the best trade-off between the available options. Using
`(any-hover: hover)` would mean users would get sticky hover states when
tapping on an iPad if they have a mouse or trackpad connected, which
feels wrong to me because in those cases touch is still likely the
primary method of interaction.
Sites built with this feature in mind will be treating hover styles as
progressive enhancement, so it seems better to me that using an iPad
with a mouse would not have hover styles, vs. having sticky hover styles
in the same situation.
Of course users can always override this with whatever they want, so
making this the default isn't locking anyone in to a particular choice.
---------
Co-authored-by: Adam Wathan <[email protected]>
Co-authored-by: Robin Malfait <[email protected]>1 parent a270e2c commit abde4c9
File tree
7 files changed
+249
-153
lines changed- packages/tailwindcss
- src
- compat
7 files changed
+249
-153
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
46 | 70 | | |
47 | 71 | | |
48 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1919 | 1919 | | |
1920 | 1920 | | |
1921 | 1921 | | |
1922 | | - | |
1923 | | - | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
1924 | 1926 | | |
1925 | 1927 | | |
1926 | 1928 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
193 | 195 | | |
194 | 196 | | |
195 | 197 | | |
196 | | - | |
197 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
198 | 202 | | |
199 | 203 | | |
200 | 204 | | |
| |||
390 | 394 | | |
391 | 395 | | |
392 | 396 | | |
393 | | - | |
394 | | - | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
395 | 401 | | |
396 | 402 | | |
397 | 403 | | |
398 | 404 | | |
399 | 405 | | |
400 | 406 | | |
401 | | - | |
402 | | - | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
403 | 411 | | |
404 | 412 | | |
405 | 413 | | |
| |||
420 | 428 | | |
421 | 429 | | |
422 | 430 | | |
423 | | - | |
424 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
425 | 435 | | |
426 | 436 | | |
427 | | - | |
428 | | - | |
429 | | - | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
430 | 442 | | |
431 | 443 | | |
432 | 444 | | |
| |||
627 | 639 | | |
628 | 640 | | |
629 | 641 | | |
630 | | - | |
631 | | - | |
632 | | - | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
633 | 645 | | |
634 | | - | |
635 | | - | |
636 | | - | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
637 | 649 | | |
| 650 | + | |
638 | 651 | | |
639 | 652 | | |
640 | 653 | | |
| 654 | + | |
641 | 655 | | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
646 | 660 | | |
647 | 661 | | |
648 | 662 | | |
| |||
672 | 686 | | |
673 | 687 | | |
674 | 688 | | |
675 | | - | |
676 | | - | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
677 | 693 | | |
678 | 694 | | |
679 | 695 | | |
680 | 696 | | |
681 | 697 | | |
682 | 698 | | |
683 | | - | |
684 | | - | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
685 | 703 | | |
686 | 704 | | |
687 | 705 | | |
| |||
715 | 733 | | |
716 | 734 | | |
717 | 735 | | |
718 | | - | |
719 | | - | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
720 | 740 | | |
721 | 741 | | |
722 | 742 | | |
723 | 743 | | |
724 | 744 | | |
725 | 745 | | |
726 | | - | |
727 | | - | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
728 | 750 | | |
729 | 751 | | |
730 | | - | |
731 | | - | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
732 | 758 | | |
733 | 759 | | |
734 | | - | |
735 | | - | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
736 | 766 | | |
737 | 767 | | |
738 | | - | |
739 | | - | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
740 | 772 | | |
741 | 773 | | |
742 | | - | |
743 | | - | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
744 | 778 | | |
745 | 779 | | |
746 | 780 | | |
747 | 781 | | |
748 | 782 | | |
749 | 783 | | |
750 | | - | |
751 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
752 | 788 | | |
753 | 789 | | |
754 | | - | |
755 | | - | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
756 | 794 | | |
757 | 795 | | |
758 | 796 | | |
| |||
763 | 801 | | |
764 | 802 | | |
765 | 803 | | |
766 | | - | |
767 | | - | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
768 | 808 | | |
769 | 809 | | |
770 | 810 | | |
| |||
2104 | 2144 | | |
2105 | 2145 | | |
2106 | 2146 | | |
2107 | | - | |
2108 | | - | |
| 2147 | + | |
| 2148 | + | |
| 2149 | + | |
| 2150 | + | |
2109 | 2151 | | |
2110 | 2152 | | |
2111 | 2153 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15660 | 15660 | | |
15661 | 15661 | | |
15662 | 15662 | | |
15663 | | - | |
15664 | | - | |
15665 | | - | |
15666 | | - | |
| 15663 | + | |
| 15664 | + | |
| 15665 | + | |
| 15666 | + | |
| 15667 | + | |
| 15668 | + | |
15667 | 15669 | | |
15668 | 15670 | | |
15669 | 15671 | | |
| |||
0 commit comments