File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -526,3 +526,32 @@ test('Custom functional @utility', async () => {
526
526
expect ( classNames ) . toContain ( 'example-xs' )
527
527
expect ( classMap . get ( 'example-xs' ) ?. modifiers ) . toEqual ( [ 'foo' , 'bar' ] )
528
528
} )
529
+
530
+ test ( 'Theme keys with underscores are suggested with underscores' , async ( ) => {
531
+ let input = css `
532
+ @import 'tailwindcss/utilities' ;
533
+
534
+ @theme {
535
+ /* Disable the spacing scale */
536
+ --spacing : initial;
537
+
538
+ /* This will get suggeted with a dot because its surrounded by numbers */
539
+ --spacing-1_5 : 1.5rem ;
540
+
541
+ /* This will get suggeted with an underscore */
542
+ --spacing-logo_margin : 0.875rem ;
543
+ }
544
+ `
545
+
546
+ let design = await __unstable__loadDesignSystem ( input , {
547
+ loadStylesheet : async ( _ , base ) => ( {
548
+ base,
549
+ content : '@tailwind utilities;' ,
550
+ } ) ,
551
+ } )
552
+
553
+ let entries = design . getClassList ( ) . filter ( ( [ name ] ) => name . startsWith ( 'p-' ) )
554
+
555
+ expect ( entries ) . toContainEqual ( [ 'p-1.5' , { modifiers : [ ] } ] )
556
+ expect ( entries ) . toContainEqual ( [ 'p-logo_margin' , { modifiers : [ ] } ] )
557
+ } )
Original file line number Diff line number Diff line change @@ -220,9 +220,20 @@ export function createUtilities(theme: Theme) {
220
220
* Register list of suggestions for a class
221
221
*/
222
222
function suggest ( classRoot : string , defns : ( ) => SuggestionDefinition [ ] ) {
223
+ /**
224
+ * The alpha and beta releases used `_` in theme keys to represent a `.`. This meant we used
225
+ * `--leading-1_5` instead of `--leading-1\.5` to add utilities like `leading-1.5`.
226
+ *
227
+ * We prefer the use of the escaped dot now but still want to make sure suggestions for the
228
+ * legacy key format still works as expected when surrounded by numbers.
229
+ */
230
+ const LEGACY_NUMERIC_KEY = / ( \d + ) _ ( \d + ) / g
231
+
223
232
function * resolve ( themeKeys : ThemeKey [ ] ) {
224
233
for ( let value of theme . keysInNamespaces ( themeKeys ) ) {
225
- yield value . replaceAll ( '_' , '.' )
234
+ yield value . replace ( LEGACY_NUMERIC_KEY , ( _ , a , b ) => {
235
+ return `${ a } .${ b } `
236
+ } )
226
237
}
227
238
}
228
239
You can’t perform that action at this time.
0 commit comments