Skip to content

Commit a75bbb3

Browse files
committed
revert force
1 parent ec813b9 commit a75bbb3

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

src/lib/Twig/Components/Checkbox/ListField.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@ final class ListField extends AbstractField
2626
{
2727
use ListFieldTrait;
2828

29+
/** @var array<string|int> */
2930
public array $value = [];
3031

32+
/**
33+
* @param CheckboxItem $item
34+
*
35+
* @return CheckboxItem
36+
*/
3137
protected function modifyListItem(array $item): array
3238
{
3339
$item['checked'] = in_array($item['value'], $this->value, true);

src/lib/Twig/Components/InputText/Field.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ final class Field extends AbstractField
2929

3030
public string $type = 'input-text';
3131

32+
public string $value = '';
33+
3234
/**
3335
* @return AttrMap
3436
*/
@@ -63,5 +65,7 @@ protected function configurePropsResolver(OptionsResolver $resolver): void
6365
});
6466
$resolver->setRequired(['name']);
6567
$resolver->setAllowedTypes('id', ['null', 'string']);
68+
$resolver->setDefaults(['value' => '']);
69+
$resolver->setAllowedTypes('value', 'string');
6670
}
6771
}

src/lib/Twig/Components/ListFieldTrait.php

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,36 @@
1616
* value: string|int,
1717
* label: string,
1818
* }
19+
* @phpstan-type ListItems list<ListItem>
1920
*/
2021
trait ListFieldTrait
2122
{
23+
public const string VERTICAL = 'vertical';
24+
public const string HORIZONTAL = 'horizontal';
25+
2226
public string $direction = 'vertical';
2327

24-
/** @var ListItem[] */
28+
/** @var ListItems */
2529
#[ExposeInTemplate(name: 'items', getter: 'getItems')]
2630
public array $items = [];
2731

28-
/** @return ListItem[] */
32+
/**
33+
* @return ListItems
34+
*/
2935
public function getItems(): array
3036
{
31-
return array_map(function ($item) {
37+
return array_map(function (array $item) {
3238
$listItem = $item + ['name' => $this->name, 'required' => $this->required];
3339

3440
return $this->modifyListItem($listItem);
3541
}, $this->items);
3642
}
3743

44+
/**
45+
* @param ListItem $item
46+
*
47+
* @return ListItem
48+
*/
3849
protected function modifyListItem(array $item): array
3950
{
4051
return $item;
@@ -49,7 +60,7 @@ protected function validateListFieldProps(OptionsResolver $resolver): void
4960

5061
$resolver
5162
->define('direction')
52-
->allowedValues('vertical', 'horizontal')
53-
->default('vertical');
63+
->allowedValues(self::VERTICAL, self::HORIZONTAL)
64+
->default(self::VERTICAL);
5465
}
5566
}

tests/integration/Twig/Components/InputText/FieldTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public function testMount(): void
2727
[
2828
'name' => 'title',
2929
'id' => 'title',
30-
'value' => 'Hello',
3130
'required' => true,
3231
'labelExtra' => ['class' => 'u-mb-1'],
3332
'helperTextExtra' => ['data-test' => 'help'],
@@ -39,7 +38,6 @@ public function testMount(): void
3938

4039
self::assertSame('title', $component->name, 'Prop "name" should be set on the component.');
4140
self::assertSame('title', $component->id, 'Prop "id" should be set on the component.');
42-
self::assertSame('Hello', $component->value, 'Prop "value" should be set on the component.');
4341
self::assertTrue($component->required, 'Prop "required" should be true.');
4442

4543
/** @var array<string, mixed> $label */
@@ -53,7 +51,6 @@ public function testMount(): void
5351
self::assertSame('title', $input['id'] ?? null, 'Input "id" should be set from prop.');
5452
self::assertSame('title', $input['name'] ?? null, 'Input "name" should be set from prop.');
5553
self::assertTrue((bool)($input['required'] ?? false), 'Input should have required attribute.');
56-
self::assertSame('Hello', $input['value'] ?? null, 'Input "value" should pass through.');
5754
self::assertSame('true', $input['data-ids-custom-init'] ?? null, 'Input should include data-ids-custom-init="true".');
5855
self::assertSame('ids-input u-w-full', $input['class'] ?? null, 'Input class should be merged.');
5956
self::assertSame('Type…', $input['placeholder'] ?? null, 'Input placeholder should be merged.');

tests/integration/Twig/Components/RadioButton/FieldTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function testDefaultRenderProducesWrapperAndRadioInput(): void
3838

3939
$wrapper = $this->getWrapper($crawler);
4040
$class = $this->getClassAttr($wrapper);
41-
self::assertSame('foo', $wrapper->attr('value'), 'Wrapper "value" should be passed through.');
4241
self::assertStringContainsString('ids-radio-button-field', $class, 'Wrapper should have "ids-radio-button-field" class.');
4342
self::assertStringContainsString('My label', $this->getText($wrapper), 'Wrapper should render provided label content.');
4443

0 commit comments

Comments
 (0)