Vuetify set outlined for all v-text-field by default
Asked Answered
D

2

4

Is there are simple way to change default value of props "outlined" for all "v-text-field" across entered project?

https://vuetifyjs.com/en/components/text-fields

enter image description here

Disaffection answered 24/1, 2020 at 10:13 Comment(0)
C
14

You could create a wrapper component and extends from VTextField (see treeshaking) and customise the default value(s).

import Vue from 'vue';
import { VTextField } from 'vuetify/lib';

Vue.component('TextFieldOutlined', {
  extends: VTextField,
  props: {
    outlined: {
      type: Boolean,
      default: true
    }
  }
})

Using it like:

<text-field-outlined
  label="Some label"
  clearable
  dense>
</text-field-outlined>

FWIW, extending a component means all base component's props are passed along and thus equally usable.

Cesaria answered 24/1, 2020 at 10:46 Comment(3)
Perfect. Was looking for something similar regarding the VBtn component. This is a great and simple solution.Robichaud
It should definitely be marked as the solution. That's clean, still allows to override the props at particular places if needed, and can be applied to any prop besides "outlined".Velure
What about Composition API? The "extends" is designed for Options API and does not handle the merging of the setup() hook.Nemathelminth
N
1

The extends is not good way for Vue 3 (Composition API). You need create own control based on v-text-field.

But for Vuetify 3 you need use Global configuration

I didn't try this code. But I think something like this:

createVuetify({
  defaults: {
    VTextField: { variant: 'outlined' },
  },
})
Nemathelminth answered 30/1 at 10:46 Comment(2)
Can you please give more details directly in the answer?Deandeana
Ok. I have appended some codeNemathelminth

© 2022 - 2024 — McMap. All rights reserved.