Files
malio-layer-ui/.playground/pages/composant/input/inputAutocomplete.vue
T
tristan dc33cf4135 feat(inputs): UX polish across input family + localFilter + focus scrollbar
Polish across the form input components, plus two new features and a few
standalone fixes.

Fixes
-----
* Reserve hint/error/success paragraph space (min-h-[1rem]) in 15
  components so a single error message no longer shifts neighboring grid
  cells: InputText, Email, Password, Phone, Amount, Number, Upload,
  Autocomplete, RichText, TextArea, Select, SelectCheckbox, Time,
  TimePicker, CalendarField, Checkbox.
* InputPhone: the '+' add button now follows the icon-state cascade
  (muted / primary on focus / black when filled / danger / success) like
  the other field icons instead of being permanently primary.
* Select and SelectCheckbox: chevron color follows the field state
  (muted by default, primary when open, black when an option is
  selected, danger / success on error / success) instead of always being
  text-current.
* InputTextArea: single-root component (was multi-root). The message
  wrapper used to occupy its own grid cell, breaking row-span layouts.
  Now flex flex-col, with the textarea area filling the available height
  via flex-1 and the message inside the same root.
* Disabled labels use text-m-muted (border-gray) instead of text-black/60
  (dark) across InputText, Email, Password, Amount, Phone, Upload,
  Autocomplete, TextArea, RichText. Also removes an unreachable
  peer-[&:not(:placeholder-shown):not(:focus)]:text-black/60 rule that
  twMerge was silently overriding with text-black.
* InputAutocomplete: eliminates four sources of visual jitter when
  focusing / opening a field that already has a selected value.
  - Drop peer-focus:-translate-y-[1.55rem] extra label translate.
  - Drop the .grow-height:focus padding rule (no more height growth or
    downward text shift on focus).
  - Drop focus:pl-[11px] (no more 1px horizontal jump).
  - Replace !border-b-0 with !border-b-transparent so the bottom border
    still reserves its 1px while remaining invisible against the
    dropdown.
* Select / SelectCheckbox: same anti-jitter treatment.
  - Drop .grow-height:focus padding rule (~12px height growth gone).
  - Replace !border-b-0 / !border-t-0 with !border-b-transparent /
    !border-t-transparent across danger / success / primary branches.
* Button: default width 240px -> 200px to match the form button sizing
  used across the app. Test updated to match.

Features
--------
* InputTextArea: scrollbar turns primary blue on focus
  (scrollbar-color: rgb(var(--m-primary)) transparent), matching the
  Select listbox styling.
* InputAutocomplete: new localFilter prop (default false). When enabled,
  filters the options prop client-side based on the input value
  (case-insensitive label.includes(query)), so static lists no longer
  need a @search listener. Async/API usage keeps the existing behavior.
  Playground "Simple statique" and "Avec icône à gauche" examples use
  local-filter.

Playground
----------
* client.vue: tighter grid gap (gap-y-5) plus an example error on a
  SelectCheckbox to visually exercise the message-space fix.

Tests
-----
All component test files include regression coverage for the above.
720/720 tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-29 15:43:53 +02:00

183 lines
5.2 KiB
Vue

<template>
<div class="grid grid-cols-1 items-start gap-6 md:grid-cols-2">
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Simple (statique)</h2>
<MalioInputAutocomplete
v-model="simpleValue"
label="Pays"
:options="staticOptions"
local-filter
/>
<p class="mt-2 text-sm text-m-muted">
Valeur sélectionnée : <code>{{ simpleValue ?? 'null' }}</code>
</p>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Avec icône à gauche</h2>
<MalioInputAutocomplete
v-model="leftIconValue"
label="Recherche"
icon-name="mdi:magnify"
icon-position="left"
:options="staticOptions"
local-filter
/>
</div>
<div class="rounded-lg border p-4 md:col-span-2">
<h2 class="mb-4 text-xl font-bold">Branché sur une API (simulé)</h2>
<p class="mb-3 text-sm text-m-muted">
Le parent écoute l'event <code>search</code> et alimente <code>options</code> + <code>loading</code>.
Tapez au moins 2 caractères.
</p>
<MalioInputAutocomplete
v-model="apiValue"
label="Client"
:options="apiOptions"
:loading="apiLoading"
:min-search-length="2"
icon-name="mdi:magnify"
icon-position="left"
@search="onSearchApi"
@select="onSelectApi"
/>
<p v-if="apiSelected" class="mt-2 text-sm text-m-muted">
Sélection : <code>{{ apiSelected.label }} (id={{ apiSelected.value }})</code>
</p>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Avec création (allowCreate)</h2>
<MalioInputAutocomplete
v-model="createValue"
label="Catégorie"
:options="staticOptions"
allow-create
hint="Taper Entrée pour créer une nouvelle valeur"
@create="onCreate"
/>
<p v-if="createdItems.length > 0" class="mt-2 text-sm text-m-muted">
Créés : {{ createdItems.join(', ') }}
</p>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Désactivé</h2>
<MalioInputAutocomplete
model-value="fr"
label="Pays"
:options="staticOptions"
disabled
/>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Readonly</h2>
<MalioInputAutocomplete
model-value="fr"
label="Pays"
:options="staticOptions"
readonly
/>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Avec hint</h2>
<MalioInputAutocomplete
v-model="hintValue"
label="Pays"
:options="staticOptions"
hint="Sélectionne un pays dans la liste"
/>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Erreur</h2>
<MalioInputAutocomplete
model-value="fr"
label="Pays"
:options="staticOptions"
error="Sélection invalide"
/>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Succès</h2>
<MalioInputAutocomplete
model-value="fr"
label="Pays"
:options="staticOptions"
success="Sélection valide"
/>
</div>
<div class="rounded-lg border p-4">
<h2 class="mb-4 text-xl font-bold">Liste vide</h2>
<MalioInputAutocomplete
v-model="emptyValue"
label="Recherche"
:options="[]"
no-results-text="Aucun élément disponible"
/>
</div>
</div>
</template>
<script setup lang="ts">
import {ref} from 'vue'
type Option = {label: string; value: string | number}
const staticOptions: Option[] = [
{label: 'France', value: 'fr'},
{label: 'Belgique', value: 'be'},
{label: 'Canada', value: 'ca'},
{label: 'Suisse', value: 'ch'},
{label: 'Luxembourg', value: 'lu'},
{label: 'Allemagne', value: 'de'},
{label: 'Espagne', value: 'es'},
{label: 'Italie', value: 'it'},
]
const simpleValue = ref<string | number | null>(null)
const leftIconValue = ref<string | number | null>(null)
const createValue = ref<string | number | null>(null)
const hintValue = ref<string | number | null>(null)
const emptyValue = ref<string | number | null>(null)
const createdItems = ref<string[]>([])
const onCreate = (value: string) => {
createdItems.value.push(value)
}
const apiValue = ref<string | number | null>(null)
const apiOptions = ref<Option[]>([])
const apiLoading = ref(false)
const apiSelected = ref<Option | null>(null)
const fakeClients: Option[] = [
{label: 'Yuno Malio', value: 1},
{label: 'Yuna Corp', value: 2},
{label: 'Yum Foods', value: 3},
{label: 'Yumi Studio', value: 4},
{label: 'Acme Inc.', value: 5},
{label: 'Globex Corp', value: 6},
{label: 'Initech', value: 7},
{label: 'Soylent Corp', value: 8},
]
const onSearchApi = async (query: string) => {
apiLoading.value = true
await new Promise(resolve => setTimeout(resolve, 400))
apiOptions.value = fakeClients.filter(c =>
c.label.toLowerCase().includes(query.toLowerCase()),
)
apiLoading.value = false
}
const onSelectApi = (option: Option | null) => {
apiSelected.value = option
}
</script>