Configuration
app.use(DynamicFormsInputs, options) provides the library's settings to the whole application and registers the components the options select. Per-field values are resolved by the order described below.
Density shows every density and variant combination in a live demo.
Installing the plugin
import { DynamicFormsInputs } from '@dynamicforms/vuetify-inputs';
import '@dynamicforms/vuetify-inputs/styles.css';
const app = createApp(MyApp);
app.use(vuetify);
app.use(DynamicFormsInputs, {
registerComponents: true,
registerVuetifyComponents: false,
defaultDensity: 'compact',
defaultVariant: 'outlined',
defaultTouchInterval: 90_000,
});The options argument and every option in it are optional: app.use(DynamicFormsInputs) keeps the built-in defaults. The type is DynamicFormsInputsOptions, which is VuetifyInputsSettings (the default settings) plus the two registration flags.
| Option | Type | Default | Description |
|---|---|---|---|
registerComponents | boolean | false | Registers this library's input components globally |
registerVuetifyComponents | boolean | false | Registers the Vuetify components the library's templates use |
defaultDensity | FieldDensity | unset, so 'default' applies | Application-wide density for all fields |
defaultVariant | FieldVariant | unset, so 'underlined' applies | Application-wide variant for all fields |
defaultTouchInterval | number | unset, so 60000 applies | Milliseconds between <df-file>/<df-image> keep-alive touches, application-wide |
shownErrors | (error, control, shownByDefault) => boolean | unset, so the default rule applies | Whether a component shows an error. Called for each error with the default rule's result; its return value is used. See Shown errors |
translate | TranslateFunction | unset, so the function translateStrings set applies | The translation function of the library's strings in this app, shaped like vue-i18n's t. See Localisation |
translateNamespace | string | unset | The namespace translate looks the library's keys up under |
dateTimeLocale | MaybeRef<Locale> | unset, so DateTimeLocaleConfig.dateTimeLocale applies | The date-fns locale <df-date-time> formats and parses with in this app; a component's locale prop takes precedence |
timeZone | string | unset, so the browser's zone applies | The time zone of datetime-mode <df-date-time> values in this app: an IANA name or 'wall'; a component's timeZone prop takes precedence. See Time zone |
errorText | ErrorText: (error: ErrorDescription) => RenderContentNonCallable | undefined | unset | Converts an error into the content it renders as. It runs while the errors are rendered, and what it reads reactively is tracked. See Translating errors |
anyDecimalSeparator | boolean | unset, so false applies | Whether . and , both act as the decimal separator of <df-input input-type="number"> in this app; a component's anyDecimalSeparator prop takes precedence. See Any decimal separator |
FieldDensity is 'default' | 'comfortable' | 'compact' | 'inline', FieldVariant is 'outlined' | 'plain' | 'underlined' | 'filled' | 'solo' | 'solo-inverted' | 'solo-filled' | 'inverted'. 'inverted' is the library's own; see Variant options.
The options are provided to the application under the library's settings key, and every field reads defaultDensity and defaultVariant from it.
What registerComponents registers
With registerComponents: true the plugin registers each of the library's components under its exported name. Vue resolves those names in kebab-case as well, which is how the examples in this documentation write them:
| Registered name | Written in a template as | Documentation |
|---|---|---|
DfActions | <df-actions> | df-actions |
DfCheckbox | <df-checkbox> | df-checkbox |
DfColor | <df-color> | df-color |
DfDateTime | <df-date-time> | df-date-time |
DfFile | <df-file> | df-file |
DfImage | <df-image> | df-image |
DfInput | <df-input> | df-input |
DfInputGroup | <df-input-group> | df-input-group |
DfInputHint | <df-input-hint> | df-input-hint |
DfLabel | <df-label> | input base: Label |
DfRtfEditor | <df-rtf-editor> | df-rtf-editor |
DfSelect | <df-select> | df-select |
DfTextArea | <df-text-area> | df-text-area |
Without the flag, the components are imported in the files that use them:
import { DfInput, DfSelect } from '@dynamicforms/vuetify-inputs';What registerVuetifyComponents registers
The library's templates reference Vuetify components by tag name (<v-text-field>, <v-select>, <v-menu>, ...), resolved against globally registered components at runtime. An application that installs Vuetify with its full component set has them registered. One that registers Vuetify components selectively sets registerVuetifyComponents: true, and the plugin registers the set the library uses:
VAutocomplete, VBtn, VBtnGroup, VBtnToggle, VCard, VCardActions, VCheckbox, VChip, VCol, VColorPicker, VCombobox, VConfirmEdit, VDatePicker, VDivider, VField, VFileInput, VIcon, VImg, VInput, VList, VListItem, VListItemTitle, VMenu, VNumberInput, VProgressLinear, VRow, VSelect, VSlider, VSwitch, VTextarea, VTextField, VTimePicker.
The same set is exported as VuetifyComponents, for registering it under names of the application's choice:
import { VuetifyComponents } from '@dynamicforms/vuetify-inputs';
Object.entries(VuetifyComponents).map(([name, component]) => app.component(name, component));The stylesheet
import '@dynamicforms/vuetify-inputs/styles.css';The stylesheet is a single file with every style the components need beyond Vuetify's own:
- the margins that keep fields of different types on one baseline. Each density and variant combination sets its own offsets through CSS variables on
.v-field, so a text field, a select and a checkbox on the same row are aligned. - the
inlinedensity, which Vuetify does not have. The rules under.df-density-inlinehide field outlines and floating labels and reduce padding and minimum heights to fit a table cell. - the
invisibleclass for the visibility'invisible': it hides an element and keeps its box. Vuetify hasd-none, used for'hidden', but no class that keeps the box. - the components' own styles: the
df-actionsbutton group, the multi-row select, label layout, the size of icons (see Icon size), and the RTF editor's toolbar and content area, styled to follow the application's Vuetify theme.
Cascade layer
Every rule of the stylesheet is in the cascade layer vuetify-overrides.dynamicforms-vuetify-inputs, a sub-layer of Vuetify's vuetify-overrides. The stylesheet starts with Vuetify's layer order:
@layer vuetify-core, vuetify-components, vuetify-overrides, vuetify-utilities, vuetify-final;The order is therefore the same whether the stylesheet loads before or after Vuetify's. The library's rules override Vuetify's component styles (vuetify-components) whatever their specificity. Vuetify's utility classes (vuetify-utilities, e.g. w-50, text-body-large) and the application's unlayered styles override the library's rules, also on a df component. Import vuetify/styles before vuetify/components: a component stylesheet loaded first declares vuetify-components before vuetify-core, and the core reset then overrides component styles.
Icon size
The components draw their icons with cached-icon from vue-cached-icon (3.3.1 or newer), which sizes an icon by two inherited custom properties:
| Property | Library value | vue-cached-icon default | Meaning |
|---|---|---|---|
--cached-icon-size | 1.5em | 1em | The icon's size, relative to the font size of the text around it |
--cached-icon-descent | .1667em | 0px | How far the icon reaches below the baseline, in the icon's own em |
The library sets both on the class df-component, which every component puts on its root element (DfLabel too, also when the application renders it on its own), and which also marks the content of the menus the components open (select choices, the date and colour pickers, the RTF toolbar's menus): that content is rendered in an overlay outside the component's element and inherits nothing from it. An icon in a df component is therefore 1.5em of its text, the size of a v-icon; cached-icons of the application outside df components keep vue-cached-icon's 1em.
useInputBase() includes df-component in densityClass, so a component built on it carries the class on the element that binds densityClass.
The application overrides the values on any element inside a df component, or on the class itself. The library's rule is in its cascade layer, so an unlayered rule wins whatever its specificity:
/* every df component */
.df-component {
--cached-icon-size: 1.25em;
}
/* label icons only */
.df-label {
--cached-icon-size: 1.25em;
}Setting the properties on :root or another ancestor sizes the application's own cached-icons; inside df components the library's values on .df-component take precedence, because the class is closer to the icon.
Each component puts its resolved density on its root element as df-density-default, df-density-comfortable, df-density-compact or df-density-inline, and the rules above select by those classes. Without the import, fields render unaligned and inline density renders like default.
Where density and variant come from
Both values are resolved the same way when the field is created:
const injectedDensity = inject<FieldDensity | null>('field-density', null);
const injectedVariant = inject<FieldVariant | null>('field-variant', null);
const extra = computed(() => props.control?.extra ?? {});
const density = computed(
() => props.density ?? extra.value.density ?? injectedDensity ?? settings.defaultDensity ?? 'default',
);
const variant = computed(
() => props.variant ?? extra.value.variant ?? injectedVariant ?? settings.defaultVariant ?? 'underlined',
);The density is the first value that is set, in this order: the component's density prop, the density among the bound element's extended properties, a field-density provided by any ancestor, defaultDensity from the plugin options, and 'default'. The order for variant is the same and ends in 'underlined'.
A section, e.g. a dialog's form or a table's rows, sets its own values with provide:
<template>
<tr>
<td><df-input :control="row.fields.name" /></td>
<td><df-select :control="row.fields.country" :choices="countries" /></td>
<td><df-checkbox :control="row.fields.active" density="compact" /></td>
</tr>
</template>
<script setup lang="ts">
import { provide } from 'vue';
provide('field-density', 'inline');
provide('field-variant', 'plain');
</script>Every field below that provide renders inline and plain, except the checkbox, whose prop sets compact.
The provided values are plain strings, not refs. They are read once, when the field's setup runs, so the provide must precede the field's creation; a provide in an ancestor's setup does, since its children are created afterwards. A value provided or changed later does not apply to existing fields.
Summary
| Where | How | Applies to | Takes precedence over |
|---|---|---|---|
| Component | density / variant prop | that one field | everything below |
| Bound element | density / variant extended property | that one field | everything below |
| Ancestor component | provide('field-density' / 'field-variant', value) | the subtree below it | plugin options |
| Plugin install | defaultDensity / defaultVariant option | the whole application | the baked-in values |
| Built in | — | anything left unset | — ('default' and 'underlined') |
The settings key itself is exported as vuetifyInputsSettingsKey, so a subtree may provide a whole VuetifyInputsSettings object of its own, which replaces the plugin's settings for the fields under it. For density and variant alone, field-density and field-variant are shorter.
The per-field props and the rest of the props every component shares are documented in input base.
