Skip to content

Commit b7c7e48

Browse files
authored
Add @container-size utility (#18901)
This PR adds a new `@container-size` utility instead of `@container-[size]`. The main reason we didn't do this before is because we only have container width related container queries, and not block based ones so we never needed `size` and `inline-size` was enough. However, `@container-size` is still useful if you are using container query related units such as `cqb` which are using the block size of the container not the inline size. I also added a little helper such that `@container-size` is only available in `insiders` and `4.2.0` (and later) so `4.1.x` releases won't have this utility yet. This will require some CHANGELOG changes such that we don't include this when releasing the next minor release.
1 parent 2f1cbbf commit b7c7e48

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- _Experimental_: Add `@container-size` utility ([#18901](https://github.com/tailwindlabs/tailwindcss/pull/18901))
13+
1014
### Fixed
1115

1216
- Handle `'` syntax in ClojureScript when extracting classes ([#18888](https://github.com/tailwindlabs/tailwindcss/pull/18888))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const enableContainerSizeUtility = process.env.FEATURES_ENV !== 'stable'

packages/tailwindcss/src/utilities.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26214,16 +26214,16 @@ test('@container', async () => {
2621426214
'@container-normal',
2621526215
'@container/sidebar',
2621626216
'@container-normal/sidebar',
26217-
'@container-[size]',
26218-
'@container-[size]/sidebar',
26217+
'@container-size',
26218+
'@container-size/sidebar',
2621926219
]),
2622026220
).toMatchInlineSnapshot(`
26221-
".\\@container-\\[size\\]\\/sidebar {
26222-
container: sidebar / size;
26221+
".\\@container-normal\\/sidebar {
26222+
container: sidebar;
2622326223
}
2622426224

26225-
.\\@container-normal\\/sidebar {
26226-
container: sidebar;
26225+
.\\@container-size\\/sidebar {
26226+
container: sidebar / size;
2622726227
}
2622826228

2622926229
.\\@container\\/sidebar {
@@ -26234,12 +26234,12 @@ test('@container', async () => {
2623426234
container-type: inline-size;
2623526235
}
2623626236

26237-
.\\@container-\\[size\\] {
26238-
container-type: size;
26239-
}
26240-
2624126237
.\\@container-normal {
2624226238
container-type: normal;
26239+
}
26240+
26241+
.\\@container-size {
26242+
container-type: size;
2624326243
}"
2624426244
`)
2624526245
expect(
@@ -26248,8 +26248,8 @@ test('@container', async () => {
2624826248
'-@container-normal',
2624926249
'-@container/sidebar',
2625026250
'-@container-normal/sidebar',
26251-
'-@container-[size]',
26252-
'-@container-[size]/sidebar',
26251+
'-@container-size',
26252+
'-@container-size/sidebar',
2625326253
]),
2625426254
).toEqual('')
2625526255
})

packages/tailwindcss/src/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from './ast'
1313
import type { Candidate, CandidateModifier, NamedUtilityValue } from './candidate'
1414
import type { DesignSystem } from './design-system'
15+
import { enableContainerSizeUtility } from './feature-flags'
1516
import type { Theme, ThemeKey } from './theme'
1617
import { compareBreakpoints } from './utils/compare-breakpoints'
1718
import { DefaultMap } from './utils/default-map'
@@ -5712,6 +5713,12 @@ export function createUtilities(theme: Theme) {
57125713
value = candidate.value.value
57135714
} else if (candidate.value.kind === 'named' && candidate.value.value === 'normal') {
57145715
value = 'normal'
5716+
} else if (
5717+
enableContainerSizeUtility &&
5718+
candidate.value.kind === 'named' &&
5719+
candidate.value.value === 'size'
5720+
) {
5721+
value = 'size'
57155722
}
57165723

57175724
if (value === null) return

0 commit comments

Comments
 (0)