Files
malio-layer-ui/app/components/malio/input/InputTextArea.test.ts
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

187 lines
5.8 KiB
TypeScript

import {describe, expect, it} from 'vitest'
import {mount} from '@vue/test-utils'
import type {DefineComponent} from 'vue'
import InputTextArea from './InputTextArea.vue'
type InputTextAreaProps = {
id?: string
label?: string
name?: string
autocomplete?: string
modelValue?: string | null
size?: number | string
textInput?: string
textLabel?: string
required?: boolean
maxLength?: number
showCounter?: boolean
disabled?: boolean
readonly?: boolean
hint?: string
error?: string
success?: string
rounded?: string
}
const InputTextAreaForTest = InputTextArea as DefineComponent<InputTextAreaProps>
describe('MalioInputTextArea', () => {
it('renders the initial textarea value', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {modelValue: 'initial textarea value'},
})
expect(wrapper.get('textarea').element.value).toBe('initial textarea value')
})
it('renders the label text and reuses a provided id', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {id: 'custom-textarea-id', label: 'Description'},
})
expect(wrapper.get('textarea').attributes('id')).toBe('custom-textarea-id')
expect(wrapper.get('label').attributes('for')).toBe('custom-textarea-id')
expect(wrapper.get('label').text()).toBe('Description')
})
it('generates an id when missing', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {label: 'Description'},
})
const textareaId = wrapper.get('textarea').attributes('id')
expect(textareaId?.startsWith('malio-input-textarea-')).toBe(true)
expect(wrapper.get('label').attributes('for')).toBe(textareaId)
})
it('applies name, autocomplete and rows attributes', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {name: 'bio', autocomplete: 'on', size: 4},
})
expect(wrapper.get('textarea').attributes('name')).toBe('bio')
expect(wrapper.get('textarea').attributes('autocomplete')).toBe('on')
expect(wrapper.get('textarea').attributes('rows')).toBe('4')
})
it('sets required, readonly and disabled attributes', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {
required: true,
readonly: true,
disabled: true,
},
})
expect(wrapper.get('textarea').attributes('required')).toBeDefined()
expect(wrapper.get('textarea').attributes('readonly')).toBeDefined()
expect(wrapper.get('textarea').attributes('disabled')).toBeDefined()
expect(wrapper.get('textarea').classes()).toContain('cursor-not-allowed')
})
it('emits update:modelValue on input change', async () => {
const wrapper = mount(InputTextAreaForTest, {
props: {modelValue: ''},
})
await wrapper.get('textarea').setValue('new textarea value')
expect(wrapper.emitted('update:modelValue')?.[0]).toEqual(['new textarea value'])
})
it('shows the character counter when enabled', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {
modelValue: 'hello',
showCounter: true,
maxLength: 20,
},
})
expect(wrapper.get('span.text-xs').text()).toBe('5/20')
expect(wrapper.get('textarea').classes()).toContain('pb-6')
})
it('shows hint message in muted color', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {hint: 'Helpful hint'},
})
expect(wrapper.get('p.text-m-muted').text()).toBe('Helpful hint')
})
it('shows error state on textarea and label', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {
label: 'Description',
error: 'Textarea error',
},
})
expect(wrapper.get('textarea').classes()).toContain('border-m-danger')
expect(wrapper.get('label').classes()).toContain('text-m-danger')
expect(wrapper.get('p.text-m-danger').text()).toBe('Textarea error')
expect(wrapper.get('textarea').attributes('aria-invalid')).toBe('true')
})
it('shows success state on textarea and label', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {
label: 'Description',
success: 'Textarea success',
},
})
expect(wrapper.get('textarea').classes()).toContain('border-m-success')
expect(wrapper.get('label').classes()).toContain('text-m-success')
expect(wrapper.get('p.text-m-success').text()).toBe('Textarea success')
})
it('prioritizes error over success', () => {
const wrapper = mount(InputTextAreaForTest, {
props: {
error: 'Textarea error',
success: 'Textarea success',
},
})
expect(wrapper.get('textarea').classes()).toContain('border-m-danger')
expect(wrapper.find('p.text-m-success').exists()).toBe(false)
expect(wrapper.get('p.text-m-danger').text()).toBe('Textarea error')
})
it('renders as a single root element (works as a single grid item)', () => {
const host = document.createElement('div')
document.body.appendChild(host)
const wrapper = mount(InputTextAreaForTest, {
attachTo: host,
})
// host > div[data-v-app] > component roots
const app = host.firstElementChild as HTMLElement
expect(app.children.length).toBe(1)
wrapper.unmount()
host.remove()
})
it('applies primary scrollbar class on focus', async () => {
const wrapper = mount(InputTextAreaForTest)
expect(wrapper.get('textarea').classes()).not.toContain('textarea-scrollbar-primary')
await wrapper.get('textarea').trigger('focus')
expect(wrapper.get('textarea').classes()).toContain('textarea-scrollbar-primary')
})
it('removes primary scrollbar class on blur', async () => {
const wrapper = mount(InputTextAreaForTest)
await wrapper.get('textarea').trigger('focus')
await wrapper.get('textarea').trigger('blur')
expect(wrapper.get('textarea').classes()).not.toContain('textarea-scrollbar-primary')
})
})