Count a text field's characters against its maximum
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
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
71442831ff
commit
c8c2d2e13e
@@ -147,6 +147,29 @@ it('collects a file field\'s own errors and each file\'s', function () {
|
||||
->toContain('photo.jpg is larger than 2 GB.');
|
||||
});
|
||||
|
||||
it('counts the characters of a field that has a maximum', function () {
|
||||
$html = (string) $this->blade('<x-input id="bio" label="Bio" hint="Shown on your profile" maxlength="60" counter />');
|
||||
|
||||
expect($html)
|
||||
->toContain('class="field-support-row"')
|
||||
->toContain('class="field-counter"')
|
||||
->toContain('maxlength="60"')
|
||||
->toContain('max: 60,')
|
||||
->toContain('>0/60</span>')
|
||||
->toContain('aria-live="polite"')
|
||||
->toContain('Shown on your profile');
|
||||
|
||||
expect((string) $this->blade('<x-textarea id="note" label="Note" maxlength="140" counter />'))
|
||||
->toContain('class="field-counter"')
|
||||
->toContain('>0/140</span>');
|
||||
});
|
||||
|
||||
it('shows no counter without `counter` or without a maximum to count against', function () {
|
||||
expect((string) $this->blade('<x-input label="Bio" maxlength="60" />'))->not->toContain('field-counter')
|
||||
->and((string) $this->blade('<x-input label="Bio" counter />'))->not->toContain('field-counter')
|
||||
->and((string) $this->blade('<x-textarea label="Note" counter />'))->not->toContain('field-counter');
|
||||
});
|
||||
|
||||
it('lays out a form with its actions under an optional divider', function () {
|
||||
$html = (string) $this->blade(<<<'BLADE'
|
||||
<x-form wire:submit="save" separator>
|
||||
|
||||
Reference in New Issue
Block a user