Set default full-width for <UInput> in Nuxt UI
How can I make all <UInput> components default to w-full without manually adding the class each time?
Looking for a global/default override—ideally via app.vue, a plugin, or config—so that all input fields stretch full width by default when wrapped in FormField.
Any clean solutions?
3 Replies
Hi @mubaidr. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
You can make all
<UInput>
components default to full width by customizing the theme in your app.config.ts
file. Based on the knowledge sources, Nuxt UI allows you to customize component styling through theme configuration.
The best approach would be to modify the formField
component configuration since you mentioned you're wrapping your inputs in FormField
. Here's how you can do it:
1. Create or modify your app.config.ts
file in the root of your project:
This approach is clean because:
1. It's centralized in your app configuration
2. It doesn't require modifying each individual component
3. It follows Nuxt UI's recommended theming approach
The FormField
component, as shown in the FormField documentation, provides a container for form elements, and by adding w-full
to the container slot, all child inputs will inherit the full width behavior.
If you're using Nuxt UI Pro, the same approach applies, but you might need to adjust the configuration structure slightly according to the Pro version's theme structure.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@255041865672294410> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
I have used following hack to make this hsppen for now:
and then add custom css: