Skip to content

Commit 59936c6

Browse files
authored
Add tab-* utilities (#20022)
This PR adds new `tab-*` utilities. The `tab-*` utilities set the `tab-size` property. They support positive integer bare values, and arbitrary values: | Class | CSS | | -- | -- | | `tab-2` | `tab-size: 2;` | | `tab-[12px]` | `tab-size: 12px;` | This also adds `tab-size` to the property order near the other text layout properties. ## Test plan 1. Added new `tab-*` utility tests 2. Updated the intellisense snapshot 3. Other existing tests still pass
1 parent 90a2373 commit 59936c6

5 files changed

Lines changed: 60 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Allow using `@variant` with stacked variants (e.g. `@variant hover:focus { … }`) ([#19996](https://github.com/tailwindlabs/tailwindcss/pull/19996))
1515
- Allow using `@variant` with compound variants (e.g. `@variant hover, focus { … }`) ([#19996](https://github.com/tailwindlabs/tailwindcss/pull/19996))
1616
- Support `--default(…)` in `--value(…)` and `--modifier(…)` for functional `@utility` definitions ([#19989](https://github.com/tailwindlabs/tailwindcss/pull/19989))
17-
- Add `zoom-*` utilities ([#20020](https://github.com/tailwindlabs/tailwindcss/pull/20020))
1817
- Add `scrollbar-gutter-*` utilities ([#20018](https://github.com/tailwindlabs/tailwindcss/pull/20018))
18+
- Add `zoom-*` utilities ([#20020](https://github.com/tailwindlabs/tailwindcss/pull/20020))
19+
- Add `tab-*` utilities ([#20022](https://github.com/tailwindlabs/tailwindcss/pull/20022))
1920

2021
### Fixed
2122

packages/tailwindcss/src/__snapshots__/intellisense.test.ts.snap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11492,6 +11492,9 @@ exports[`getClassList 1`] = `
1149211492
"stroke-transparent/95",
1149311493
"stroke-transparent/100",
1149411494
"subpixel-antialiased",
11495+
"tab-2",
11496+
"tab-4",
11497+
"tab-8",
1149511498
"table",
1149611499
"table-auto",
1149711500
"table-caption",

packages/tailwindcss/src/property-order.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ export default [
360360
'text-overflow',
361361
'hyphens',
362362
'white-space',
363+
'tab-size',
363364

364365
'color',
365366
'text-transform',

packages/tailwindcss/src/utilities.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11865,6 +11865,50 @@ test('whitespace', async () => {
1186511865
).toEqual('')
1186611866
})
1186711867

11868+
test('tab', async () => {
11869+
expect(
11870+
await compileCss(
11871+
css`
11872+
@theme {
11873+
--tab-size-github: 8;
11874+
}
11875+
11876+
@tailwind utilities;
11877+
`,
11878+
['tab-2', 'tab-8', 'tab-[12px]', 'tab-[3]'],
11879+
),
11880+
).toMatchInlineSnapshot(`
11881+
"
11882+
.tab-2 {
11883+
tab-size: 2;
11884+
}
11885+
11886+
.tab-8 {
11887+
tab-size: 8;
11888+
}
11889+
11890+
.tab-\\[3\\] {
11891+
tab-size: 3;
11892+
}
11893+
11894+
.tab-\\[12px\\] {
11895+
tab-size: 12px;
11896+
}
11897+
"
11898+
`)
11899+
expect(
11900+
await run([
11901+
'tab',
11902+
'-tab-2',
11903+
'tab-2.5',
11904+
'tab-1/2',
11905+
'tab-unknown',
11906+
'tab-2/foo',
11907+
'tab-[12px]/foo',
11908+
]),
11909+
).toEqual('')
11910+
})
11911+
1186811912
test('text-wrap', async () => {
1186911913
expect(await run(['text-wrap', 'text-nowrap', 'text-balance', 'text-pretty']))
1187011914
.toMatchInlineSnapshot(`

packages/tailwindcss/src/utilities.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,16 @@ export function createUtilities(theme: Theme) {
22942294
staticUtility('whitespace-pre-wrap', [['white-space', 'pre-wrap']])
22952295
staticUtility('whitespace-break-spaces', [['white-space', 'break-spaces']])
22962296

2297+
functionalUtility('tab', {
2298+
handleBareValue: ({ value }) => {
2299+
if (!isPositiveInteger(value)) return null
2300+
return value
2301+
},
2302+
handle: (value) => [decl('tab-size', value)],
2303+
})
2304+
2305+
suggest('tab', () => [{ values: ['2', '4', '8'] }])
2306+
22972307
staticUtility('text-wrap', [['text-wrap', 'wrap']])
22982308
staticUtility('text-nowrap', [['text-wrap', 'nowrap']])
22992309
staticUtility('text-balance', [['text-wrap', 'balance']])

0 commit comments

Comments
 (0)