F
Filamentβ€’16mo ago
rg.block

->extraAttribute not working on TextInput

I have this TextInput on a form inside an app I just upgraded to v3. TextInput::make('status') ->label('Status') ->extraAttributes(['class' => 'text-teal-600']) ->disabled(), That exact code used to work on v2, but on V3 the text color does not change. I also tried ->extraInputAttribute but no luck. Is there something odd that I need to look for? The TextInput is inside Grid\Section.
59 Replies
neverender24
neverender24β€’16mo ago
I don't seem to have problem with this. Forms\Components\TextInput::make('name') ->required() ->extraAttributes(['class' => 'sample']) ->maxLength(255), In my theme.css .sample { background: red !important; } seems to work with me
neverender24
neverender24β€’16mo ago
Med
Medβ€’16mo ago
maybe the class is missing in the css file
Dennis Koch
Dennis Kochβ€’16mo ago
Do you have a custom theme? Otherwise there won’t be a teal color class in there
but on V3 the text color does not change.
Check your HTML. The class is probably there.
rg.block
rg.blockOPβ€’16mo ago
I do have a theme. On v2 I had this in my tailwind.config.js: theme: { extend: { colors: { primary: colors.teal, danger: colors.rose, success: colors.sky, warning: colors.yellow, },... and using ->extraAttributes(['class' => 'text-teal-600']) was working just fine. Inspecting the element, I see the class but no color change. I am not aware of anything different with v3, but perhaps I need to do it a different way?
Dennis Koch
Dennis Kochβ€’16mo ago
Do you have your theme included via Vite and npm run dev running?
rg.block
rg.blockOPβ€’16mo ago
I do have npm run dev running, and I do not have the theme included via vite. I did not have that either under v2. When you say theme, are you referring to having theme.css file like: https://filamentphp.com/docs/3.x/panels/themes ? When I say theme, I am referring to the them section of my tailwind.config.js
Dennis Koch
Dennis Kochβ€’16mo ago
Yes. I am referring to Filament themes. You have one right? Or to which file does your tailwind.config apply?
rg.block
rg.blockOPβ€’16mo ago
I think I am following the issue better. On v2 I was using filament.css which I was including via vite like: input: [ // ... 'resources/css/filament.css', ], But when I upgraded to v3 that went away and inside fillament.css @import '../../vendor/filament/filament/resources/css/app.css'; does not exist anymore. I am still a bit confused as to what changed from v2 to v3 in this respect, but I am going to try with a new theme file following the link I sent you. Actually, reading through the docs, isnt that for a panel theme? I am using tables and form on full page livewire components.
Dennis Koch
Dennis Kochβ€’16mo ago
Ah sorry. Didn't notice that. So no theme for you and keep your filament.css file. Is that one included and ran throught Vite/Webpack though?
rg.block
rg.blockOPβ€’16mo ago
Yes, I added filament.css file back and is included under vite. But even then, using extend on the tailwind config should preserve any default values and add the ones I listed like the ones here so even if I did not have one it should work no? tailwind.config.js theme: { extend: { colors: { primary: colors.teal, danger: colors.rose, success: colors.sky, warning: colors.yellow, }, ...
Dennis Koch
Dennis Kochβ€’16mo ago
Yes I think that should work. Do you have /app/Livewire/**/*.php or similar in your tailwind config?
rg.block
rg.blockOPβ€’16mo ago
I dont, here is most of what I have: const colors = require('tailwindcss/colors') const plugin = require('tailwindcss/plugin') import preset from './vendor/filament/support/tailwind.config.preset' export default { presets: [preset], darkMode: 'class', content: [ './app/Filament/**/*.php', './resources/views/filament/**/*.blade.php', './vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php', './vendor/laravel/jetstream/**/*.blade.php', './storage/framework/views/*.php', './resources/views/**/*.blade.php', './resources/**/*.blade.php', './vendor/filament/**/*.blade.php', './vendor/awcodes/filament-table-repeater/resources/views/**/*.blade.php', ], theme: { extend: { colors: { primary: colors.teal, danger: colors.rose, success: colors.sky, warning: colors.yellow, },
Dennis Koch
Dennis Kochβ€’16mo ago
Okay, is your Form component in the Filament or Livewire folder? You need to add it's path to Tailwind.
rg.block
rg.blockOPβ€’16mo ago
My form component is inside app/Livewire so I added './app/Livewire/*.php', but same result
Dennis Koch
Dennis Kochβ€’16mo ago
npm run dev still running and it recompiled the theme?
rg.block
rg.blockOPβ€’16mo ago
yes
Dennis Koch
Dennis Kochβ€’16mo ago
Hm. I am running out of ideas. Can you try an undefined color: I think bg-[red] should work and check whether it's included in the CSS file
rg.block
rg.blockOPβ€’16mo ago
bg-[red] does indeed set the background color to red, let me check the CSS file
Dennis Koch
Dennis Kochβ€’16mo ago
Yeah, will be included then. Maybe extend doesn't keep the defaults then. Can you try this for tailwind config:
colors: {
primary: colors.teal,
danger: colors.rose,
success: colors.sky,
warning: colors.yellow,
...colors,
},
colors: {
primary: colors.teal,
danger: colors.rose,
success: colors.sky,
warning: colors.yellow,
...colors,
},
rg.block
rg.blockOPβ€’16mo ago
Adding colors under theme (not under extend) gives me some other issues related to other css I am using on non filament components. It messes up different things but it still does not set the text color. I am going to take a break until the morning (pacific time), and continue with it then. Thanks for sticking with me. β˜• or 🍺 on me.
Dennis Koch
Dennis Kochβ€’16mo ago
Not under theme. Still under extend. But add the last line: ...colors
rg.block
rg.blockOPβ€’16mo ago
Still nothing with that. I just get additional warnings on run dev regarding deprecated colors
Dennis Koch
Dennis Kochβ€’16mo ago
Thanks for sticking with me. β˜• or 🍺 on me.
Thanks. Appreciate it.
rg.block
rg.blockOPβ€’16mo ago
No problem, my github handle is different but I think the pic looks similar 🀣
Dennis Koch
Dennis Kochβ€’16mo ago
Hm, really weird. We verified that it picks up custom classes from your Livewire file and your build process is running. So there must be something off with the colors config. Running out of ideas. Sorry.
trovster
trovsterβ€’16mo ago
Did you add this line to the tailwind config with ** folder matching?
rg.block
rg.blockOPβ€’16mo ago
I dont think it should be any different than a regular form, but my form is part of an Action on a standalone table, that should have no effect on the styles right? I did, I tried with and without it
trovster
trovsterβ€’16mo ago
Also, not sure if it matters, but I restart npm run dev after making tailwind.config.js changes.
rg.block
rg.blockOPβ€’16mo ago
Yeah, I dont think it should since I see that it reloads the file but I still restart it just in case and nothing
Dennis Koch
Dennis Kochβ€’16mo ago
Shouldn't be a difference if it picks up custom classes on this I think. Do you have any console errors?
rg.block
rg.blockOPβ€’16mo ago
No console errors
Med
Medβ€’16mo ago
set up a custom theme following v3 docs, and then npm run build not dev
Med
Medβ€’16mo ago
you created a new theme using php artisan command?
Dennis Koch
Dennis Kochβ€’16mo ago
It's not a panel.
rg.block
rg.blockOPβ€’16mo ago
I did not, my comment was that it is not a panel
rg.block
rg.blockOPβ€’16mo ago
I see this as even more weird. The class gets added, then it is listed under the styles, and it shows under the app.css compiled file
Med
Medβ€’16mo ago
the input has a text class you can't change the color from the parent element
Dennis Koch
Dennis Kochβ€’16mo ago
Argh. You need ->extraInputAttributes() and probably !text-teal-600 I thought it wasn't listed under styles at all πŸ™ˆ
rg.block
rg.blockOPβ€’16mo ago
No worries....I did try with ->extraInputAttributes on my original post, I just tried again with and without ! and still no color change
trovster
trovsterβ€’16mo ago
[&_*]:text-teal-600 I think
rg.block
rg.blockOPβ€’16mo ago
You can see the class being applied to the input element there, and even see that the gray is crosssed out since the other class has important but nothing
trovster
trovsterβ€’16mo ago
Oh, it has been added to the input. But the first screenshot showed it added to the parent div.
rg.block
rg.blockOPβ€’16mo ago
yeah, then I added ->extraInputAttributes as mentioned by Med and Dennis, but no luck yet
trovster
trovsterβ€’16mo ago
And you've typed text, not just placeholder?
rg.block
rg.blockOPβ€’16mo ago
TextInput::make('status') ->label('Status') ->extraInputAttributes(['class' => '!text-teal-600']) ->disabled(),
trovster
trovsterβ€’16mo ago
Ah, the input is disabled. There is a different class applied for that.
rg.block
rg.blockOPβ€’16mo ago
you are indeed right, if I remove the disabled to test it out I see the color
rg.block
rg.blockOPβ€’16mo ago
I think this is the issue
Dennis Koch
Dennis Kochβ€’16mo ago
Okay, so you want that color also for disabled input?
->extraInputAttributes(['class' => '!text-teal-600 !disabled:[-webkit-text-fill-color:theme(colors.teal.600)]'])
->extraInputAttributes(['class' => '!text-teal-600 !disabled:[-webkit-text-fill-color:theme(colors.teal.600)]'])
Damn. That's hell of a selector πŸ˜…
trovster
trovsterβ€’16mo ago
There is also placeholder and dark mode to consider
rg.block
rg.blockOPβ€’16mo ago
This one still did not work, the disabled one is still taking precedence.
Med
Medβ€’16mo ago
you added disabled:text-teal-500?
rg.block
rg.blockOPβ€’16mo ago
No, I added: ->extraInputAttributes(['class' => '!text-teal-600 !disabled:[-webkit-text-fill-color:theme(colors.teal.600)]'])
trovster
trovsterβ€’16mo ago
Well, there is another disabled selector, before the webkit one.
Med
Medβ€’16mo ago
replace it with text-teal-600 disabled:text-teal-600
rg.block
rg.blockOPβ€’16mo ago
I did that as well and nothing
trovster
trovsterβ€’16mo ago
!
Want results from more Discord servers?
Add your server