Skip to content

Commit a321e3c

Browse files
Add variants for orientation media feature (tailwindlabs#6046)
* Add variants for orientation media feature * Rename to portrait and landscape Co-authored-by: Adam Wathan <adam.wathan@gmail.com>
1 parent d261531 commit a321e3c

File tree

7 files changed

+23
-7
lines changed

7 files changed

+23
-7
lines changed

src/corePlugins.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ export let variantPlugins = {
165165
addVariant(screen.name, `@media ${query}`)
166166
}
167167
},
168+
169+
orientationVariants: ({ addVariant }) => {
170+
addVariant('portrait', '@media (orientation: portrait)')
171+
addVariant('landscape', '@media (orientation: landscape)')
172+
},
168173
}
169174

170175
export let corePlugins = {

src/lib/setupContextUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ function resolvePlugins(context, root) {
518518
variantPlugins['darkVariants'],
519519
variantPlugins['printVariant'],
520520
variantPlugins['screenVariants'],
521+
variantPlugins['orientationVariants'],
521522
]
522523

523524
return [...corePluginList, ...beforeVariants, ...userPlugins, ...afterVariants, ...layerPlugins]

tests/kitchen-sink.test.css

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,6 @@ div {
509509
}
510510
}
511511
}
512-
@media (orientation: portrait) {
513-
.portrait\:text-center {
514-
text-align: center;
515-
}
516-
}
517512
@media (min-width: 1280px) and (max-width: 1535px) {
518513
.range\:text-right {
519514
text-align: right;

tests/kitchen-sink.test.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<link rel="stylesheet" href="./tailwind.css" />
99
</head>
1010
<body>
11-
<div class="portrait:text-center range:text-right multi:text-left"></div>
11+
<div class="range:text-right multi:text-left"></div>
1212
<div
1313
class="container hover:container sm:container md:container text-center sm:text-center md:text-center"
1414
></div>

tests/kitchen-sink.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ test('it works', () => {
1111
theme: {
1212
extend: {
1313
screens: {
14-
portrait: { raw: '(orientation: portrait)' },
1514
range: { min: '1280px', max: '1535px' },
1615
multi: [{ min: '640px', max: '767px' }, { max: '868px' }],
1716
},

tests/variants.test.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,3 +906,15 @@
906906
}
907907
}
908908
}
909+
@media (orientation: portrait) {
910+
.portrait\:bg-yellow-300 {
911+
--tw-bg-opacity: 1;
912+
background-color: rgb(253 224 71 / var(--tw-bg-opacity));
913+
}
914+
}
915+
@media (orientation: landscape) {
916+
.landscape\:bg-yellow-300 {
917+
--tw-bg-opacity: 1;
918+
background-color: rgb(253 224 71 / var(--tw-bg-opacity));
919+
}
920+
}

tests/variants.test.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
<div class="lg:animate-spin"></div>
136136
<div class="hover:animate-spin"></div>
137137

138+
<!-- Orientation variants -->
139+
<div class="portrait:bg-yellow-300"></div>
140+
<div class="landscape:bg-yellow-300"></div>
141+
138142
<!-- Stacked variants -->
139143
<div class="open:hover:bg-red-200"></div>
140144
<div class="file:hover:bg-blue-600"></div>

0 commit comments

Comments
 (0)