vuetifyjs/vuetify

[Feature Request] Support Adjacent Labels on VField through label-variant

開放

#22,053 建立於 2025年9月13日

 (4 則留言) (5 個反應) (1 位負責人)TypeScript (7,139 個分叉)batch import
C: VTextFieldP: highS: maybeT: featurehelp wanted

倉庫指標

星標
 (40,995 顆星)
PR 合併指標
 (平均合併 59天 10小時) (30 天內合併 8 個 PR)

描述

Problem to solve

The Material 3 design guidance allows for adjacent labels.

Currently there is no way to allow this on the existing inputs without some hacky css overrides and defaults.

There is the ability to specify the label separately and not pass the label to the input, but this makes the label reacting to the input focus and other usability concerns. (not as convenient as a label prop) Also has the drawback of requiring a refactor if you decide to switch between the layout variants.

Proposed solution

Create a new VField prop called label-variant, which supports the following:

  • default - (float)
  • float
  • single-line or inline
  • adjacent or above
  • fixed - permanently puts in the floating state, like persistent-placeholder

This would likely also mean deprecating the single-line prop, which isn't very descriptive of it's function anyway.

Adding this prop would then allow the developer to set the preference in the global defaults and override easily without having to implement two template systems for labels.

Code like this:

<script setup>
  import { ref } from 'vue'

  const text = defineModel()
  const isLabelActive = ref(false)
</script>

<template>
  <div>
    <v-label
      text="Label"
      :class="{'active-label': isLabelActive}"
    />
    <v-text-field
      v-model="text"
      color="primary"
      @focus="isLabelActive = true"
      @blur="isLabelActive = false"
    />
  </div>
</template>

<style scoped>
  .active-label {
    color: rgb(var(--v-theme-primary));
    opacity: 1;
    font-weight: 500;
  }
</style>

would become:

<v-text-field
  v-model="text"
  color="primary"
  label="Label"
  label-variant="adjacent"
/>

貢獻者指南