Skip to content

Fix lowercase+uppercase keys (camelCase/PascalCase) unexpectedly treated to kebab-case when using JavaScript config file #18115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ test('config values can be merged into the theme', () => {
lg: ['1.125rem', '2'],
xl: ['1.5rem', '3rem', 'invalid'],
'2xl': ['2rem'],
LargeTitle: ['28px', { fontWeight: 700, lineHeight: '36px' }],
},

letterSpacing: {
Expand Down Expand Up @@ -117,6 +118,7 @@ test('config values can be merged into the theme', () => {
])
expect(theme.resolve('2xl', ['--text'])).toEqual('2rem')
expect(theme.resolveWith('2xl', ['--text'], ['--line-height'])).toEqual(['2rem', {}])
expect(theme.resolve('LargeTitle', ['--text'])).toEqual('28px')
expect(theme.resolve('super-wide', ['--tracking'])).toEqual('0.25em')
expect(theme.resolve('super-loose', ['--leading'])).toEqual('3')
expect(theme.resolve('1/2', ['--width'])).toEqual('60%')
Expand Down
10 changes: 6 additions & 4 deletions packages/tailwindcss/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,12 @@ export class Theme {
candidateValue !== null ? (`${namespace}-${candidateValue}` as ThemeKey) : namespace

if (!this.values.has(themeKey)) {
// If the exact theme key is not found, we might be trying to resolve a key containing a dot
// that was registered with an underscore instead:
if (candidateValue !== null && candidateValue.includes('.')) {
themeKey = `${namespace}-${candidateValue.replaceAll('.', '_')}` as ThemeKey
if (candidateValue !== null) {
// If the exact theme key is not found, we might be trying to resolve a key:
// - containing a dot that was registered with an underscore instead
// - containing a lowercase alphabet followed by an uppercase one that was replaced to kebab case
themeKey =
`${namespace}-${candidateValue.replaceAll('.', '_').replace(/([a-z])([A-Z])/g, (_, a, b) => `${a}-${b.toLowerCase()}`)}` as ThemeKey

if (!this.values.has(themeKey)) continue
} else {
Expand Down