Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Fix ButtonGroup not showing active state if value are numbers #10916

Open
wants to merge 8 commits into
base: 5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions resources/js/components/fieldtypes/ButtonGroupFieldtype.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
ref="button"
type="button"
:name="name"
@click="updateSelectedOption($event.target.value)"
@click="updateSelectedOption(option.value)"
:value="option.value"
:disabled="isReadOnly"
:class="{'active': value === option.value}"
:class="{'active': value == option.value}"
v-text="option.label || option.value"
/>
</div>
Expand Down
37 changes: 32 additions & 5 deletions tests/Fieldtypes/HasSelectOptionsTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,68 @@ trait HasSelectOptionsTests
#[DataProvider('optionsProvider')]
public function it_preloads_options($options, $expected)
{
$field = $this->field(['options' => $options]);
$fieldType = $this->field(['options' => $options]);

$this->assertArrayHasKey('options', $preloaded = $field->preload());
$this->assertEquals($expected, $preloaded['options']);
$this->assertArrayHasKey('options', $preloaded = $fieldType->preload());

// Use json_encode data to strictly check all data types as well, which assertEquals ignores.
$this->assertJsonStringEqualsJsonString(json_encode($expected), json_encode($preloaded['options']));
}

#[Test]
#[DataProvider('optionsProvider')]
public function it_augments_single_values($options, $expected)
{
$fieldType = $this->field(['options' => $options]);

if (! in_array(MultipleLabeledValueTests::class, class_uses_recursive(self::class))) {
$this->assertSame($fieldType->augment(50)?->value(), 50);
$this->assertSame($fieldType->augment('50')?->value(), 50);
$this->assertSame($fieldType->augment(100)?->value(), 100);
$this->assertSame($fieldType->augment('100')?->value(), 100);
$this->assertSame($fieldType->augment('one')?->value(), 'one');
} else {
$this->expectNotToPerformAssertions();
}
}

public static function optionsProvider()
{
return [
'list' => [
['one', 'two', 'three'],
['one', 'two', 'three', 50, '100'],
[
['value' => 'one', 'label' => 'one'],
['value' => 'two', 'label' => 'two'],
['value' => 'three', 'label' => 'three'],
['value' => 50, 'label' => 50],
['value' => '100', 'label' => '100'],
],
],
'associative' => [
['one' => 'One', 'two' => 'Two', 'three' => 'Three'],
['one' => 'One', 'two' => 'Two', 'three' => 'Three', 50 => '50', '100' => 100],
[
['value' => 'one', 'label' => 'One'],
['value' => 'two', 'label' => 'Two'],
['value' => 'three', 'label' => 'Three'],
['value' => 50, 'label' => '50'],
['value' => 100, 'label' => 100],
],
],
'multidimensional' => [
[
['key' => 'one', 'value' => 'One'],
['key' => 'two', 'value' => 'Two'],
['key' => 'three', 'value' => 'Three'],
['key' => 50, 'value' => 50],
['key' => '100', 'value' => 100],
],
[
['value' => 'one', 'label' => 'One'],
['value' => 'two', 'label' => 'Two'],
['value' => 'three', 'label' => 'Three'],
['value' => 50, 'label' => 50],
['value' => '100', 'label' => 100],
],
],
];
Expand Down
Loading