Skip to content
API 风格:

Sélecteur ​

LhSelect permet de choisir une valeur dans une liste d'options, avec support des options désactivées, de l'effacement et de la navigation clavier.

Utilisation de base ​

Utilisation de base
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhSelect } from '@lh-ui/vue3'

const selectedCity = ref('beijing')
const cityOptions = [
  { label: 'Pékin', value: 'beijing' },
  { label: 'Shanghai', value: 'shanghai' },
  { label: 'Shenzhen', value: 'shenzhen' },
]
</script>

<template>
  <!-- Utilisation de base -->
  <LhSelect v-model="selectedCity" :options="cityOptions" placeholder="Veuillez choisir une ville" />
</template>
vue
<script>
import { LhSelect } from '@lh-ui/vue3'

export default {
  components: { LhSelect },
  data() {
    return {
      selectedCity: 'beijing',
      cityOptions: [
        { label: 'Pékin', value: 'beijing' },
        { label: 'Shanghai', value: 'shanghai' },
        { label: 'Shenzhen', value: 'shenzhen' },
      ],
    }
  },
}
</script>

<template>
  <!-- Utilisation de base -->
  <LhSelect v-model="selectedCity" :options="cityOptions" placeholder="Veuillez choisir une ville" />
</template>

Effaçable et désactivé ​

Effaçable et désactivé
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhSelect } from '@lh-ui/vue3'

const selectedRegion = ref('')
const selectedDisabled = ref('north')
const regionOptions = [
  { label: 'Chine du Nord', value: 'north' },
  { label: "Chine de l'Est", value: 'east' },
  { label: 'Chine du Sud', value: 'south' },
]
const disabledOptions = [
  { label: 'Chine du Nord', value: 'north', disabled: true },
  { label: "Chine de l'Est", value: 'east' },
  { label: 'Chine du Sud', value: 'south' },
]
</script>

<template>
  <!-- Effaçable -->
  <LhSelect v-model="selectedRegion" :options="regionOptions" clearable placeholder="Veuillez choisir une région" />
  <!-- Désactivé -->
  <LhSelect v-model="selectedDisabled" :options="disabledOptions" disabled placeholder="Désactivé" />
</template>
vue
<script>
import { LhSelect } from '@lh-ui/vue3'

export default {
  components: { LhSelect },
  data() {
    return {
      selectedRegion: '',
      selectedDisabled: 'north',
      regionOptions: [
        { label: 'Chine du Nord', value: 'north' },
        { label: "Chine de l'Est", value: 'east' },
        { label: 'Chine du Sud', value: 'south' },
      ],
      disabledOptions: [
        { label: 'Chine du Nord', value: 'north', disabled: true },
        { label: "Chine de l'Est", value: 'east' },
        { label: 'Chine du Sud', value: 'south' },
      ],
    }
  },
}
</script>

<template>
  <!-- Effaçable -->
  <LhSelect v-model="selectedRegion" :options="regionOptions" clearable placeholder="Veuillez choisir une région" />
  <!-- Désactivé -->
  <LhSelect v-model="selectedDisabled" :options="disabledOptions" disabled placeholder="Désactivé" />
</template>

Thème personnalisé ​

Appliquez une couleur de thème personnalisée au sélecteur.

Thème porcelaine bleue
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhConfigProvider, LhSelect } from '@lh-ui/vue3'

const selectedTheme = ref('beijing')
const cityOptions = [
  { label: 'Pékin', value: 'beijing' },
  { label: 'Shanghai', value: 'shanghai' },
]
const cerblueTheme = {
  'primary-color': '#2B4C7C',
  'primary-color-hover': '#3D649E',
  'primary-color-bg': '#E8EDF3',
}
</script>

<template>
  <LhConfigProvider :theme-vars="cerblueTheme">
    <!-- Thème porcelaine bleue -->
    <LhSelect v-model="selectedTheme" :options="cityOptions" placeholder="Veuillez choisir" />
  </LhConfigProvider>
</template>
vue
<script>
import { LhConfigProvider, LhSelect } from '@lh-ui/vue3'

export default {
  components: { LhConfigProvider, LhSelect },
  data() {
    return {
      selectedTheme: 'beijing',
      cityOptions: [
        { label: 'Pékin', value: 'beijing' },
        { label: 'Shanghai', value: 'shanghai' },
      ],
      cerblueTheme: {
        'primary-color': '#2B4C7C',
        'primary-color-hover': '#3D649E',
        'primary-color-bg': '#E8EDF3',
      },
    }
  },
}
</script>

<template>
  <LhConfigProvider :theme-vars="cerblueTheme">
    <!-- Thème porcelaine bleue -->
    <LhSelect v-model="selectedTheme" :options="cityOptions" placeholder="Veuillez choisir" />
  </LhConfigProvider>
</template>

Pour plus de thèmes, consultez Personnalisation du thème.

Internationalisation ​

Le sélecteur peut être internationalisé via LhConfigProvider et la fonction t.

Internationalisation
vue
<script setup lang="ts">
import { ref, computed } from 'vue'
import { LhConfigProvider, LhSelect, LhButton, zhCN, enUS } from '@lh-ui/vue3'

const locale = ref('zh-CN')
const selected = ref('beijing')
const cityOptions = [
  { label: 'Pékin', value: 'beijing' },
  { label: 'Shanghai', value: 'shanghai' },
  { label: 'Shenzhen', value: 'shenzhen' },
]
const messages = computed(() => (locale.value === 'zh-CN' ? zhCN : enUS))
</script>

<template>
  <LhConfigProvider :locale="messages">
    <!-- Sélection de la ville -->
    <LhSelect
      v-model="selected"
      :options="cityOptions"
      :placeholder="locale === 'zh-CN' ? '请选择城市' : 'Please select city'"
    />
    <!-- Changement de langue -->
    <LhButton @click="locale = locale === 'zh-CN' ? 'en-US' : 'zh-CN'">
      {{ locale === 'zh-CN' ? '切换至英文' : 'Switch to Chinese' }}
    </LhButton>
  </LhConfigProvider>
</template>
vue
<script>
import { LhConfigProvider, LhSelect, LhButton, zhCN, enUS } from '@lh-ui/vue3'

export default {
  components: { LhConfigProvider, LhSelect, LhButton },
  data() {
    return {
      locale: 'zh-CN',
      selected: 'beijing',
      cityOptions: [
        { label: 'Pékin', value: 'beijing' },
        { label: 'Shanghai', value: 'shanghai' },
        { label: 'Shenzhen', value: 'shenzhen' },
      ],
    }
  },
  computed: {
    messages() {
      return this.locale === 'zh-CN' ? zhCN : enUS
    },
  },
}
</script>

<template>
  <LhConfigProvider :locale="messages">
    <!-- Sélection de la ville -->
    <LhSelect
      v-model="selected"
      :options="cityOptions"
      :placeholder="locale === 'zh-CN' ? '请选择城市' : 'Please select city'"
    />
    <!-- Changement de langue -->
    <LhButton @click="locale = locale === 'zh-CN' ? 'en-US' : 'zh-CN'">
      {{ locale === 'zh-CN' ? '切换至英文' : 'Switch to Chinese' }}
    </LhButton>
  </LhConfigProvider>
</template>

Tailles ​

Tailles
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhSelect } from '@lh-ui/vue3'

const demoSizeSmall = ref('a')
const demoSizeMedium = ref('a')
const demoSizeLarge = ref('a')
const sizeOptions = [
  { label: 'Option 1', value: 'a' },
  { label: 'Option 2', value: 'b' },
  { label: 'Option 3', value: 'c' },
]
</script>

<template>
  <!-- small -->
  <LhSelect v-model="demoSizeSmall" :options="sizeOptions" size="small" placeholder="small" />
  <!-- medium -->
  <LhSelect v-model="demoSizeMedium" :options="sizeOptions" size="medium" placeholder="medium" />
  <!-- large -->
  <LhSelect v-model="demoSizeLarge" :options="sizeOptions" size="large" placeholder="large" />
</template>
vue
<script>
import { LhSelect } from '@lh-ui/vue3'

export default {
  components: { LhSelect },
  data() {
    return {
      demoSizeSmall: 'a',
      demoSizeMedium: 'a',
      demoSizeLarge: 'a',
      sizeOptions: [
        { label: 'Option 1', value: 'a' },
        { label: 'Option 2', value: 'b' },
        { label: 'Option 3', value: 'c' },
      ],
    }
  },
}
</script>

<template>
  <!-- small -->
  <LhSelect v-model="demoSizeSmall" :options="sizeOptions" size="small" placeholder="small" />
  <!-- medium -->
  <LhSelect v-model="demoSizeMedium" :options="sizeOptions" size="medium" placeholder="medium" />
  <!-- large -->
  <LhSelect v-model="demoSizeLarge" :options="sizeOptions" size="large" placeholder="large" />
</template>

Accessibilité et conteneur de montage ​

aria-label fournit une description d'accessibilité, name est le nom natif du formulaire, et popper-container indique le conteneur de montage du panneau déroulant.

Accessibilité et conteneur de montage
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhSelect } from '@lh-ui/vue3'

const demoA11y = ref('')
const demoContainer = ref('')
const sizeOptions = [
  { label: 'Option 1', value: 'a' },
  { label: 'Option 2', value: 'b' },
  { label: 'Option 3', value: 'c' },
]
</script>

<template>
  <!-- aria-label et name -->
  <LhSelect v-model="demoA11y" :options="sizeOptions" aria-label="Veuillez choisir une ville" name="city" placeholder="aria-label et name" />
  <!-- Monté sur body -->
  <LhSelect v-model="demoContainer" :options="sizeOptions" popper-container="body" placeholder="Monté sur body" />
</template>
vue
<script>
import { LhSelect } from '@lh-ui/vue3'

export default {
  components: { LhSelect },
  data() {
    return {
      demoA11y: '',
      demoContainer: '',
      sizeOptions: [
        { label: 'Option 1', value: 'a' },
        { label: 'Option 2', value: 'b' },
        { label: 'Option 3', value: 'c' },
      ],
    }
  },
}
</script>

<template>
  <!-- aria-label et name -->
  <LhSelect v-model="demoA11y" :options="sizeOptions" aria-label="Veuillez choisir une ville" name="city" placeholder="aria-label et name" />
  <!-- Monté sur body -->
  <LhSelect v-model="demoContainer" :options="sizeOptions" popper-container="body" placeholder="Monté sur body" />
</template>

API Select ​

Props ​

PropDescriptionTypeValeur par défaut
modelValueValeur actuelleunknown—
optionsListe des options[LhSelectOption](#type-LhSelectOption)[]() => []
placeholderTexte d'occupation (en l'absence de valeur, utilise le pack de langue select.placeholder, en chinois « 请选择 »)string''
disabledDésactivé ou nonbooleanfalse
clearableAfficher ou non le bouton d'effacementbooleanfalse
sizeTaille du sélecteur"small" | "medium" | "large"'medium'
name—string—
ariaLabelTexte d'aide en l'absence de libellé visiblestring—
popperContainer—string | HTMLElement'body'
sxProps de mise en page sxLhSxProps—

Events ​

ÉvénementDescriptionParamètre
update:modelValueLa valeur changevalue: unknown
changeLa sélection changevalue, option
clearClic sur effacer—

Option ​

ts
type LhSelectOption = {
  label: string
  value: unknown
  disabled?: boolean
}

Les touches ArrowUp et ArrowDown déplacent le surlignage, Entrée confirme la sélection, et Échap ferme le menu déroulant.

Définitions de types ​

Ce composant exporte les structures de types TypeScript suivantes (extraites automatiquement de packages/components/select/src/types.ts et des sources @lh-ui/share/core/* ; cliquez sur chaque entrée pour déplier la définition complète ; la description des props se trouve dans le tableau Props ci-dessus) :

LhSelectSize
ts
export type LhSelectSize = 'small' | 'medium' | 'large'
LhSelectProps
ts
export interface LhSelectProps {
  modelValue?: unknown
  options?: LhSelectOption[]
  placeholder?: string
  disabled?: boolean
  clearable?: boolean
  size?: LhSelectSize
  name?: string
  ariaLabel?: string
  popperContainer?: 'body' | HTMLElement | string
  /** Props de mise en page sx */
  sx?: LhSxProps
}
LhSelectOption (provenant de @lh-ui/share/core/select)
ts
export interface LhSelectOption {
  label: string
  value: unknown
  disabled?: boolean
}

Slots ​

SlotDescriptionContenu par défaut
emptyContenu personnalisé de l'état vide du panneau déroulant lorsque les options sont épuiséesPack de langue select.noData (en chinois « 暂无数据 »)

La beauté de la tradition, la fondation du code