# Composer / input

Input một dòng của Classic: ba size, trạng thái error và disabled, tên truy cập do caller nối.

## Key rules

- Classic: dùng `Input` với `size` small, medium hoặc large; chiều cao lấy từ `chatty:h-8`, `chatty:h-10`, `chatty:h-12`.
- Classic: `Input` không render label và không render message lỗi; caller nối `htmlFor`/`id` và `aria-describedby`.
- Classic: `error` chỉ đổi viền sang `chatty:border-destructive`; caller thêm `aria-invalid` và thông báo.
- Classic: PopupBody vẽ focus-visible cho input bằng outline 2px; chữ input giữ role mobile 18px; tối đa 500px có sàn 16px.
- `Input` là field một giá trị; vùng soạn tin nhiều dòng không dùng component này.

## Use when / Avoid

Dùng cho dữ liệu một dòng như email hoặc tên. Không dùng placeholder làm label duy nhất. Vùng soạn tin và textarea là build riêng, không phải `Input`.

### Use instead

| Component | Use when |
| --- | --- |
| `Input` | Field một dòng; Classic FormField dùng cho trường form. |
| `textarea` | Field nhiều dòng; FormField dùng native textarea riêng. |

## Live preview

Example — Input thật: large, error, read-only và disabled.

```jsx
import React from 'react';
import {Input} from '@avada/chatty-ui/components/input.js';

export function Fields() {
  return (
    <div>
      <label htmlFor="small-email">Small</label>
      <Input id="small-email" size="small" defaultValue="customer@example.com" />
      <label htmlFor="medium-email">Medium</label>
      <Input id="medium-email" size="medium" defaultValue="customer@example.com" />
      <label htmlFor="email">Large</label>
      <Input id="email" type="email" size="large" defaultValue="customer@example.com" />
      <label htmlFor="invalid-email">Email with error</label>
      <Input
        id="invalid-email"
        error
        aria-invalid="true"
        aria-describedby="email-error"
        defaultValue="invalid"
      />
      <p id="email-error">Enter a valid email address.</p>
      <label htmlFor="locked-email">Read-only email</label>
      <Input id="locked-email" readOnly value="customer@example.com" />
      <label htmlFor="disabled-email">Disabled email</label>
      <Input id="disabled-email" disabled value="customer@example.com" />
    </div>
  );
}
```

## Classic

### Import / element

| Component / element | Import / file | Scope root |
| --- | --- | --- |
| `Input` | @avada/chatty-ui | .chatty-widget > #Avada-FAQ_Widget > .Avada-Faqs_Popup |

### Anatomy

| Part | Element |
| --- | --- |
| 1 | Native `input`; `type` mặc định là text. |
| 2 | Label và message lỗi do caller đặt ngoài component. |

### Placement / order

| Context | Order |
| --- | --- |
| Form chiến dịch | FormField render `Input` với `placeholder`; label không nằm trong `Input`. |

### Props

| Prop | Type | Values | Default | Notes |
| --- | --- | --- | --- | --- |
| `size` | string | small, medium, large | `medium` | Chọn height và padding ngang. |
| `type` | string | HTML input type | `text` | Chuyển vào native input. |
| `error` | boolean | true, false | `false` | Đổi viền sang destructive. |
| `disabled` | boolean | true, false | `false` | Thêm `chatty:bg-muted` khi disabled. |
| `className` | string | CSS classes | undefined | Gộp cuối danh sách class. |
| `props` | attributes | Native attrs, handlers, ARIA | Caller | Spread vào input; caller đặt tên truy cập. |

### Sizes

| Size | Height | Padding | Gap | Radius | Font role (px/rem) | Hit target | Breakpoint / mechanism |
| --- | --- | --- | --- | --- | --- | --- | --- |
| small | Derived(32px = h-8 × 4px) | Derived(12px = px-3 × 4px) | Không khai báo | 8px (`chatty:rounded-md`) | input-value Derived(15px = type(input-value, desktop, size)) / Derived(22px = type(input-value, desktop, line)); weight 400 | Native box | Mobile role Derived(18px = type(input-value, mobile, size)) / Derived(24px = type(input-value, mobile, line)); tối đa 500px có sàn 16px, không giảm role |
| medium | Derived(40px = h-10 × 4px) | Derived(12px = px-3 × 4px) | Không khai báo | 8px (`chatty:rounded-md`) | input-value Derived(15px = type(input-value, desktop, size)) / Derived(22px = type(input-value, desktop, line)); weight 400 | Native box | Mobile role Derived(18px = type(input-value, mobile, size)) / Derived(24px = type(input-value, mobile, line)); tối đa 500px có sàn 16px, không giảm role |
| large | Derived(48px = h-12 × 4px) | Derived(16px = px-4 × 4px) | Không khai báo | 8px (`chatty:rounded-md`) | input-value Derived(15px = type(input-value, desktop, size)) / Derived(22px = type(input-value, desktop, line)); weight 400 | Native box | Mobile role Derived(18px = type(input-value, mobile, size)) / Derived(24px = type(input-value, mobile, line)); tối đa 500px có sàn 16px, không giảm role |

### Tokens

| Part | Token | Light | Dark |
| --- | --- | --- | --- |
| Background | `--chatty-background` | #ffffff | Merchant `--faqsBgColor` |
| Text | `--chatty-foreground` | #0f172a | Merchant `--faqsTextColor` |
| Placeholder | `--chatty-muted-foreground` | #64748b | Merchant `--faqsTextColorSecondary` |
| Border | `--chatty-border` | #e2e8f0 | #e2e8f0 |
| Error border | `--chatty-destructive` | #ef4444 | #ef4444 |
| Disabled fill | `--chatty-muted` | #f1f5f9 | #f1f5f9 |
| Focus ring | `--chatty-ring` | Merchant `--faqsTextColor`, fallback #303030 | Merchant `--faqsTextColor`, fallback #eee |

### States

| State | Trigger | Visual change (values) | ARIA/attribute |
| --- | --- | --- | --- |
| Default | render | `chatty:border-border`, `chatty:bg-background` | Không thêm ARIA |
| Hover | pointer | Nền giữ `--chatty-background`; Input không có viền hover riêng | Native |
| Focus-visible | keyboard | outline 2px solid `--chatty-ring`, offset 2px | Native focus |
| Error | `error` true | `chatty:border-destructive` | Caller đặt aria-invalid |
| Disabled | `disabled` | `chatty:disabled:opacity-50`, `chatty:disabled:cursor-not-allowed`, `chatty:bg-muted` | Native disabled |
| Read-only | readOnly attribute | Không có style riêng; giá trị vẫn đọc và chọn được | Native readonly |

### Behaviour

| Interaction | Result |
| --- | --- |
| Keyboard | Native input nhận gõ và Tab; disabled bị loại khỏi Tab. |
| Màn hình hẹp | Tối đa 500px: dùng max(16px, var(--chatty-type-input-value-size, 16px)) để giữ role và tránh iOS phóng to. |
| Lỗi | `error` chỉ đổi viền; message và ARIA do caller cấp. |

### Copy

| String | i18n key | Where |
| --- | --- | --- |
| Placeholder | Caller-owned | `placeholder` truyền từ FormField |
| Label / lỗi | Caller-owned | Ngoài component |

### Source

| File | Evidence |
| --- | --- |
|  | API và element |
|  | Token và focus Classic |
|  | Caller |

## Do / Don't

Do: nối label bằng `htmlFor` và `id`; lỗi nối bằng `aria-describedby`.

Don't: chỉ đổi màu viền để báo lỗi.

## Accessibility

| Surface | Role / name | Keyboard / focus | Live region | Contrast pair / ratio |
| --- | --- | --- | --- | --- |
| Classic | `input` native; tên từ label của caller | Tab vào field; outline 2px offset 2px khi focus-visible | Caller-owned | Text Measured(#0f172a / #ffffff = 17.85:1); border Measured(#e2e8f0 / #ffffff = 1.23:1) |

## Target

```target
| Surface | Now | Target | Source |
| --- | --- | --- | --- |
| Classic | Viền mặc định `--chatty-border` đo thấp hơn 3:1 trên nền trắng | Not in code yet — build with the body values. Viền field đạt 3:1 với nền thật; đo lại trên palette merchant. | [WCAG — non text contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html) |
| Classic | `error` chỉ đổi màu viền | Not in code yet — build with the body values. Thêm message lỗi gắn aria-describedby và aria-invalid khi error true. | [WCAG — error identification](https://www.w3.org/WAI/WCAG22/Understanding/error-identification.html) |
| Classic | Input React một dòng | Not available — new build follows Target. Element (dự kiến): `chatty-text-field`, form-associated (`setFormValue`, `setValidity`); nhãn qua attribute `label` hoặc slot `label`, slot `help`; part `control`; input đặt trong shadow, nếu autofill hỏng thì cho `<input slot="input">` ở light DOM. | [MDN: ElementInternals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals) |
```


- [WCAG — non text contrast](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)
- [WCAG — error identification](https://www.w3.org/WAI/WCAG22/Understanding/error-identification.html)
- [MDN: ElementInternals](https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals)
