Different units and dynamic variable values#4677
Different units and dynamic variable values#4677davidwebca wants to merge 3 commits intoalpinejs:mainfrom
Conversation
I extended the functionality of the existing collapse plugin to allow using any known CSS unit or any CSS variable.
Ex.:
```x-collapse.min.var(--collapse-min)``` will now work.
```x-collapse.min.100lvh``` will now work.
```x-collapse.min.100``` still fallbacks to pixels.
The variable detection hence allows Tailwind to set arbitrary values to variables with responsive variants.
```
<div class="[--collapse-min:100px] lg:[--collapse-min:500px]" x-collapse.min.var(--collapse-min)>
Example content
</div>
```
The example above allows us to set a minimum height to 100px on mobile and to 500px on desktop (lg screen size in Tailwind).
Maybe issue? : parentheses aren't technically in the spec for HTML attributes, but supported in all major browsers.
… add tests - Reverted all gratuitous semicolons and style reformatting - Fixed regex that wouldn't match single-digit values (e.g. 5px) - Fixed unitMatch check that could never be falsy - Fixed null dereference when match fails - Fixed string concatenation bug in transition start height - Changed floor default from 0 to '0px' for consistent string type - Simplified modifierValue parsing logic - Added tests for unitless values and CSS variables Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
PR Review: #4677 — Different units and dynamic variable valuesType: Feature What's happening (plain English)Currently,
The core change is small: instead of Other approaches considered
The modifier approach is the right call — it's consistent with how Changes MadeI substantially rewrote the contributor's implementation. The original PR had several issues:
Test Results
Code ReviewThe final implementation is clean and minimal — only 3 lines changed in the main Concern about parentheses in HTML attributes: The contributor noted that Scope question: This is a nice-to-have feature with modest community demand (2 rocket reactions, references 3 issues). The implementation is small and non-breaking. But it does expand the API surface of the collapse plugin. SecurityNo security concerns identified. VerdictNeeds discussion — the implementation is solid after my fixes, and the feature has a real use case (responsive collapse heights with Tailwind). But I want you to weigh in on:
If you're good with the feature, it's ready to merge. I've fixed all the issues and added tests. Reviewed by Claude |
I extended the functionality of the existing collapse plugin to allow using any known CSS unit or any CSS variable.
Ex.:
x-collapse.min.var(--collapse-min)will now work.x-collapse.min.100lvhwill now work.x-collapse.min.100still fallbacks to pixels.The variable detection hence allows Tailwind to set arbitrary values to variables with responsive variants.
The example above allows us to set a minimum height to 100px on mobile and to 500px on desktop (lg screen size in Tailwind).
Maybe issue? : parentheses aren't technically in the spec for HTML attributes, but supported in all major browsers.
Adresses #2282, #2984 and might invalidate #4547