Land a caller's style with its class on field and picker roots
Plan step 38 review: the showcase kept two unlayered width classes because <x-input> and <x-datepicker> "don't forward style usefully". They did not: the Phase F rule is that a caller's class and style land on the component root, and the field family sent class to the field's root but style to the inner control, where a width sizes nothing. Input, password, textarea, select and file now pass style to the field root with class; datepicker and timepicker put it on their root; <x-group> dropped style entirely and <x-split-button> gave it to the leading button; <x-search> rendered it twice, on the root and the input. A textarea given a style also lost its autogrow rows, since its own style attribute came second and the browser ignores it. A dataset test renders each component with both and requires them on the root, once. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Qwx5USif3wFFmxtHg5U1g9
This commit is contained in:
co-authored by
Claude Opus 5
parent
3fb0a404db
commit
cd47aa4b0f
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* A caller's `class` and `style` land on a component's root, untouched and once (the Phase F rule
|
||||
* in docs/plans/material-3-alignment-brief.md): an application's width or margin sizes the whole
|
||||
* component, whichever element its other attributes reach. The field family, the pickers and the
|
||||
* components that split their attributes between a root and an inner control are the ones that
|
||||
* can get it wrong, so each is rendered here with both.
|
||||
*/
|
||||
it('lands a caller\'s class and style on the root, and only there', function (string $blade) {
|
||||
$html = (string) $this->blade($blade);
|
||||
|
||||
preg_match('/<([a-z]+)((?:[^>"\']|"[^"]*"|\'[^\']*\')*)>/', ltrim($html), $root);
|
||||
|
||||
expect($root[2] ?? '')
|
||||
->toContain('class="caller-class')
|
||||
->toContain('--caller-width: 192px')
|
||||
->and(substr_count($html, 'caller-class'))->toBe(1, 'the class lands more than once')
|
||||
->and(substr_count($html, '--caller-width'))->toBe(1, 'the style lands more than once');
|
||||
})->with([
|
||||
'input' => '<x-input label="Name" class="caller-class" style="--caller-width: 192px" />',
|
||||
'password' => '<x-password label="Password" class="caller-class" style="--caller-width: 192px" />',
|
||||
'textarea' => '<x-textarea label="Message" class="caller-class" style="--caller-width: 192px" />',
|
||||
'textarea, fixed height' => '<x-textarea label="Message" :autogrow="false" class="caller-class" style="--caller-width: 192px" />',
|
||||
'select' => '<x-select label="Expiry" :options="[]" class="caller-class" style="--caller-width: 192px" />',
|
||||
'file' => '<x-file label="Attachments" class="caller-class" style="--caller-width: 192px" />',
|
||||
'datepicker' => '<x-datepicker label="From" class="caller-class" style="--caller-width: 192px" />',
|
||||
'timepicker' => '<x-timepicker label="At" class="caller-class" style="--caller-width: 192px" />',
|
||||
'choices' => '<x-choices label="Days" :options="[]" class="caller-class" style="--caller-width: 192px" />',
|
||||
'search' => '<x-search placeholder="Search" class="caller-class" style="--caller-width: 192px" />',
|
||||
'group' => '<x-group label="Theme" name="theme" :options="[[\'id\' => 1, \'name\' => \'One\']]" class="caller-class" style="--caller-width: 192px" />',
|
||||
'split button' => '<x-split-button label="Save" class="caller-class" style="--caller-width: 192px" />',
|
||||
'checkbox' => '<x-checkbox label="Tick" class="caller-class" style="--caller-width: 192px" />',
|
||||
'radio' => '<x-radio label="Pick" name="pick" :options="[[\'id\' => 1, \'name\' => \'One\']]" class="caller-class" style="--caller-width: 192px" />',
|
||||
'toggle' => '<x-toggle label="On" class="caller-class" style="--caller-width: 192px" />',
|
||||
'slider' => '<x-slider label="Volume" class="caller-class" style="--caller-width: 192px" />',
|
||||
]);
|
||||
|
||||
it('keeps a textarea\'s own row count beside a caller\'s style', function () {
|
||||
$html = (string) $this->blade('<x-textarea label="Message" rows="2" max-rows="6" style="max-width: 320px" />');
|
||||
|
||||
// A second style attribute on the <textarea> would be ignored by the browser, rows and all.
|
||||
preg_match('/<textarea\b(?:[^>"]|"[^"]*")*>/', $html, $control);
|
||||
|
||||
expect(substr_count($control[0] ?? '', 'style="'))->toBe(1)
|
||||
->and($control[0] ?? '')->toMatch('/style="--field-rows: 2;\s*--field-max-rows: 6;"/');
|
||||
});
|
||||
Reference in New Issue
Block a user