Skip to content

Commit

Permalink
Role field: always use radio input
Browse files Browse the repository at this point in the history
  • Loading branch information
distantnative committed Sep 7, 2024
1 parent 3540d33 commit ee6c42b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/Panel/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,10 @@ public static function role(
]);

return array_merge([
'label' => I18n::translate('role'),
'type' => count($roles) <= 1 ? 'hidden' : 'radio',
'options' => $roles
'label' => I18n::translate('role'),
'type' => count($roles) === 0 ? 'hidden' : 'radio',
'disabled' => count($roles) <= 1,
'options' => $roles
], $props);
}

Expand Down
21 changes: 12 additions & 9 deletions tests/Panel/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,10 @@ public function testRole(): void
{
$field = Field::role();
$expected = [
'label' => 'Role',
'type' => 'hidden',
'options' => []
'label' => 'Role',
'type' => 'hidden',
'disabled' => true,
'options' => []
];

$this->assertSame($expected, $field);
Expand All @@ -250,9 +251,10 @@ public function testRole(): void

$field = Field::role();
$expected = [
'label' => 'Role',
'type' => 'radio',
'options' => [
'label' => 'Role',
'type' => 'radio',
'disabled' => false,
'options' => [
[
'text' => 'Client',
'info' => 'No description',
Expand All @@ -273,9 +275,10 @@ public function testRole(): void

$field = Field::role();
$expected = [
'label' => 'Role',
'type' => 'radio',
'options' => [
'label' => 'Role',
'type' => 'radio',
'disabled' => false,
'options' => [
[
'text' => 'Admin',
'info' => 'Admin description',
Expand Down

0 comments on commit ee6c42b

Please sign in to comment.