Replace flux:textarea inline style with tailwindcss class#2629
Replace flux:textarea inline style with tailwindcss class#2629ghabriel25 wants to merge 2 commits into
flux:textarea inline style with tailwindcss class#2629Conversation
| ->add($resize ? match ($resize) { | ||
| default => 'resize', // to prevent unhandled match type when user only provide the attribute without value | ||
| 'none' => 'resize-none', | ||
| 'both' => 'resize', | ||
| 'horizontal' => 'resize-x', | ||
| 'vertical' => 'resize-y', | ||
| } : 'resize-none') |
There was a problem hiding this comment.
I think this could be improved.
If $resize is not defined this would use resize-none but the original default was resize-y.
To make sure that $resize is always defined, and defaults to vertical, you can use
$resize ??= 'vertical';just before setting the classes, and maybe remove the default in the props.
Then this block can be simplified as
| ->add($resize ? match ($resize) { | |
| default => 'resize', // to prevent unhandled match type when user only provide the attribute without value | |
| 'none' => 'resize-none', | |
| 'both' => 'resize', | |
| 'horizontal' => 'resize-x', | |
| 'vertical' => 'resize-y', | |
| } : 'resize-none') | |
| ->add(match ($resize) { | |
| 'none' => 'resize-none', | |
| 'both' => 'resize', | |
| 'horizontal' => 'resize-x', | |
| 'vertical' => 'resize-y', | |
| default => 'resize-y' | |
| }) |
what do you thnk?
calebporzio
left a comment
There was a problem hiding this comment.
Thanks @ghabriel25! Since removing an inline style can be load-bearing, I verified this one behaviorally (fresh Laravel app, Flux as a path repo, computed styles compared on main vs this branch):
resizedefault /none/horizontal/both: computedresizevalues identical in every mode.rows="auto": computedfield-sizing: contentintact, and the auto-grow behavior is unchanged (typed 8 lines into the textarea: grew 46px -> 186px on both branches).- No JS dependency: the only
textareareference in Flux's JS is a focusable-elements selector, so nothing reads or writes these inline styles. - Bonus fix worth calling out: on
main,<flux:textarea resize />(bare attribute) throws anUnhandledMatchErrorbecause the oldmatchhas no default arm. This branch renders it fine.
On @troccoli-sgr's note: $resize always has a value here — the prop defaults to 'vertical' — so the default path still produces resize-y/resize: vertical (confirmed in the computed styles above). The default arm only catches non-standard values like the bare attribute.
Two small thoughts: I'd move the default arm to the end of the match (valid where it is, but the end is where the eye expects it), and field-sizing-content / resize-x are Tailwind v4 utilities, which is fine since Flux already requires v4.
Nice cleanup — this also means user-supplied classes can actually override resize behavior now, which the old inline style silently blocked.
The scenario
Although I can't seem to reproduce this issue #2627, I think this might be better to use tailwind class on
flux:textareasince this style not exposed to Alpine likeflux:progressin #2512.We can revert it if this style need to be set dynamically using Alpine. I just never see the need of it, at least for me.
The problem
flux:textareacurrent template using inline style for resize type and field-sizing.The solution
Change inline style with tailwindcss class which can cover it all.
File Changes
stubs/resources/views/flux/textarea.blade.php