M3 lists "supporting text + character counter" as a configuration of both text-field variants; nothing in the package drew one (plan step 24, audit docs/audits/m3-alignment/inputs.md § Missing). `counter` on `<x-input>` and `<x-textarea>` now puts `n/max` at the end of the supporting-text row, counted from the control on every input, in the error colour past the maximum, and said as M3's own "Character count, 5/20" from a polite region once typing settles. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
46 lines
2.3 KiB
PHP
46 lines
2.3 KiB
PHP
{{-- A multi-line field: the text field, grown to its content.
|
|
|
|
It starts at `rows` lines (3) and grows with what is typed up to `max-rows`, then scrolls;
|
|
`:autogrow="false"` keeps it at `rows` and lets it be resized by hand, vertically only, so a
|
|
form's column never moves. The label rests on the first line rather than in the middle of the
|
|
box. `label`, `hint`, `variant`, and `counter` for M3's character counter against `maxlength`;
|
|
every other attribute reaches the `<textarea>`. --}}
|
|
|
|
@props([
|
|
'label' => null,
|
|
'hint' => null,
|
|
'hintClass' => null,
|
|
'variant' => null,
|
|
'rows' => 3,
|
|
'maxRows' => null,
|
|
'autogrow' => true,
|
|
'counter' => false,
|
|
])
|
|
|
|
@php
|
|
$model = $attributes->whereStartsWith('wire:model')->first();
|
|
$placeholder = filled($attributes->get('placeholder')) ? $attributes->get('placeholder') : ' ';
|
|
$id = $attributes->get('id') ?? 'field-'.substr(md5($model.'|'.$label.'|textarea'), 0, 12);
|
|
// A plain form's field is named, not bound: its errors are under its name (`files[]` → `files`, `a[b]` → `a.b`).
|
|
$errorKey = $model ?? (filled($attributes->get('name')) ? str_replace(['[]', '[', ']'], ['', '.', ''], (string) $attributes->get('name')) : null);
|
|
$messages = $errorKey !== null && isset($errors) ? \Illuminate\Support\Arr::flatten($errors->get($errorKey)) : [];
|
|
// M3's counter needs a maximum to count against: without `maxlength` there is nothing to show.
|
|
$max = $counter ? $attributes->get('maxlength') : null;
|
|
@endphp
|
|
|
|
<x-livewire-material::field :$id :$label :$hint :hint-class="$hintClass" :$messages :$variant :counter="$max" :class="$attributes->get('class')" :data-readonly="$attributes->get('readonly') ? '' : null">
|
|
<textarea
|
|
{{ $attributes->except(['class', 'id', 'placeholder']) }}
|
|
id="{{ $id }}"
|
|
rows="{{ (int) $rows }}"
|
|
placeholder="{{ $placeholder }}"
|
|
@if ($autogrow)
|
|
data-autogrow
|
|
style="--field-rows: {{ (int) $rows }};@if ($maxRows) --field-max-rows: {{ (int) $maxRows }};@endif"
|
|
@endif
|
|
@if ($messages !== []) aria-invalid="true" @endif
|
|
@if ($messages !== [] || filled($hint)) aria-describedby="{{ $id }}-support" @endif
|
|
class="field-control"
|
|
></textarea>
|
|
</x-livewire-material::field>
|