Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Proposal: Allow overwriting static utilities that have a namespace
  • Loading branch information
philipp-spiess committed Sep 11, 2025
commit a4714ebc4eb4cc0009ec227fd4a157002c2f0d09
43 changes: 19 additions & 24 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9770,6 +9770,25 @@ test('rounded', async () => {
border-radius: var(--radius-sm);
}"
`)
expect(
await compileCss(
css`
@theme {
--radius-full: 99999px;
}
@tailwind utilities;
`,
['rounded-full'],
),
).toMatchInlineSnapshot(`
":root, :host {
--radius-full: 99999px;
}

.rounded-full {
border-radius: var(--radius-full);
}"
`)
expect(
await run([
'-rounded',
Expand Down Expand Up @@ -9945,15 +9964,11 @@ test('rounded-t', async () => {
}

.rounded-t-full {
border-top-left-radius: 3.40282e38px;
border-top-right-radius: 3.40282e38px;
border-top-left-radius: var(--radius-full);
border-top-right-radius: var(--radius-full);
Comment on lines -9948 to 9951
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}

.rounded-t-none {
border-top-left-radius: 0;
border-top-right-radius: 0;
border-top-left-radius: var(--radius-none);
border-top-right-radius: var(--radius-none);
}
Expand Down Expand Up @@ -10012,15 +10027,11 @@ test('rounded-r', async () => {
}

.rounded-r-full {
border-top-right-radius: 3.40282e38px;
border-bottom-right-radius: 3.40282e38px;
border-top-right-radius: var(--radius-full);
border-bottom-right-radius: var(--radius-full);
}

.rounded-r-none {
border-top-right-radius: 0;
border-bottom-right-radius: 0;
border-top-right-radius: var(--radius-none);
border-bottom-right-radius: var(--radius-none);
}
Expand Down Expand Up @@ -10079,15 +10090,11 @@ test('rounded-b', async () => {
}

.rounded-b-full {
border-bottom-right-radius: 3.40282e38px;
border-bottom-left-radius: 3.40282e38px;
border-bottom-right-radius: var(--radius-full);
border-bottom-left-radius: var(--radius-full);
}

.rounded-b-none {
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
border-bottom-right-radius: var(--radius-none);
border-bottom-left-radius: var(--radius-none);
}
Expand Down Expand Up @@ -10146,15 +10153,11 @@ test('rounded-l', async () => {
}

.rounded-l-full {
border-top-left-radius: 3.40282e38px;
border-bottom-left-radius: 3.40282e38px;
border-top-left-radius: var(--radius-full);
border-bottom-left-radius: var(--radius-full);
}

.rounded-l-none {
border-top-left-radius: 0;
border-bottom-left-radius: 0;
border-top-left-radius: var(--radius-none);
border-bottom-left-radius: var(--radius-none);
}
Expand Down Expand Up @@ -10443,12 +10446,10 @@ test('rounded-tl', async () => {
}

.rounded-tl-full {
border-top-left-radius: 3.40282e38px;
border-top-left-radius: var(--radius-full);
}

.rounded-tl-none {
border-top-left-radius: 0;
border-top-left-radius: var(--radius-none);
}

Expand Down Expand Up @@ -10503,12 +10504,10 @@ test('rounded-tr', async () => {
}

.rounded-tr-full {
border-top-right-radius: 3.40282e38px;
border-top-right-radius: var(--radius-full);
}

.rounded-tr-none {
border-top-right-radius: 0;
border-top-right-radius: var(--radius-none);
}

Expand Down Expand Up @@ -10563,12 +10562,10 @@ test('rounded-br', async () => {
}

.rounded-br-full {
border-bottom-right-radius: 3.40282e38px;
border-bottom-right-radius: var(--radius-full);
}

.rounded-br-none {
border-bottom-right-radius: 0;
border-bottom-right-radius: var(--radius-none);
}

Expand Down Expand Up @@ -10623,12 +10620,10 @@ test('rounded-bl', async () => {
}

.rounded-bl-full {
border-bottom-left-radius: 3.40282e38px;
border-bottom-left-radius: var(--radius-full);
}

.rounded-bl-none {
border-bottom-left-radius: 0;
border-bottom-left-radius: var(--radius-none);
}

Expand Down
21 changes: 13 additions & 8 deletions packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export function createUtilities(theme: Theme) {
supportsFractions?: boolean
themeKeys?: ThemeKey[]
defaultValue?: string | null
fallbacks?: Record<string, AstNode[]>
handleBareValue?: (value: NamedUtilityValue) => string | null
handleNegativeBareValue?: (value: NamedUtilityValue) => string | null
handle: (value: string, dataType: string | null) => AstNode[] | undefined
Expand Down Expand Up @@ -431,6 +432,14 @@ export function createUtilities(theme: Theme) {
value = desc.handleBareValue(candidate.value)
if (!value?.includes('/') && candidate.modifier) return
}

if (value === null && desc.fallbacks) {
let fallback = desc.fallbacks[candidate.value.value]
if (fallback) {
if (candidate.modifier) return
return fallback
}
}
}

// If there is no value, don't generate any rules.
Expand Down Expand Up @@ -2125,17 +2134,13 @@ export function createUtilities(theme: Theme) {
['rounded-br', ['border-bottom-right-radius']],
['rounded-bl', ['border-bottom-left-radius']],
] as const) {
staticUtility(
`${root}-none`,
properties.map((property) => [property, '0']),
)
staticUtility(
`${root}-full`,
properties.map((property) => [property, 'calc(infinity * 1px)']),
)
functionalUtility(root, {
themeKeys: ['--radius'],
handle: (value) => properties.map((property) => decl(property, value)),
fallbacks: {
none: properties.map((property) => decl(property, '0')),
full: properties.map((property) => decl(property, 'calc(infinity * 1px)')),
},
})
}
}
Expand Down