Skip to content

Commit 961fac6

Browse files
committed
feat: ability to pass down extra classes to the form group component
1 parent 0301a6b commit 961fac6

File tree

6 files changed

+91
-2
lines changed

6 files changed

+91
-2
lines changed

resources/views/bootstrap-5/select.blade.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
<x-forms::form-group :inline-input-class="$inlineInputClass" :inline-label-class="$inlineLabelClass" :wrap="$showLabel" :label="$label ?: $label()" :name="$attributes->get('id') ?: $id()" :framework="$framework" :inline="$inline" :required="$required" :floating="$floating">
1+
<x-forms::form-group
2+
:inline-input-class="$inlineInputClass"
3+
:inline-label-class="$inlineLabelClass"
4+
:class="$formGroupClass"
5+
:wrap="$showLabel"
6+
:label="$label ?: $label()"
7+
:name="$attributes->get('id') ?: $id()"
8+
:framework="$framework"
9+
:inline="$inline"
10+
:required="$required"
11+
:floating="$floating"
12+
>
213
@if((! empty($prepend)) || (! empty($append)))
314
<div class="input-group">
415
@if(! empty($prepend))

resources/views/material-admin-26/select.blade.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
<x-forms::form-group :inline-input-class="$inlineInputClass" :inline-label-class="$inlineLabelClass" :wrap="$showLabel" :label="$label ?: $label()" :name="$attributes->get('id') ?: $id()" :framework="$framework" :inline="$inline" :required="$required" :floating="$floating">
1+
<x-forms::form-group
2+
:inline-input-class="$inlineInputClass"
3+
:inline-label-class="$inlineLabelClass"
4+
:class="$formGroupClass"
5+
:wrap="$showLabel"
6+
:label="$label ?: $label()"
7+
:name="$attributes->get('id') ?: $id()"
8+
:framework="$framework"
9+
:inline="$inline"
10+
:required="$required"
11+
:floating="$floating"
12+
>
213
@if((! empty($prepend)) || (! empty($append)))
314
<div class="input-group mb-0">
415
@if(! empty($prepend))

src/Views/Components/Select.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public function __construct(
6565
string $idField = '',
6666
public string $inlineLabelClass = '',
6767
public string $inlineInputClass = '',
68+
public string $formGroupClass = '',
6869
string $framework = ''
6970
) {
7071
parent::__construct($framework);

src/Views/Components/Select2.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function __construct(
5656
bool $floating = false,
5757
string $inlineLabelClass = '',
5858
string $inlineInputClass = '',
59+
string $formGroupClass = '',
5960
string $framework = ''
6061
) {
6162
if ($allowClear && empty($placeholder)) {
@@ -86,6 +87,7 @@ public function __construct(
8687
idField: $idField,
8788
inlineLabelClass: $inlineLabelClass,
8889
inlineInputClass: $inlineInputClass,
90+
formGroupClass: $formGroupClass,
8991
framework: $framework
9092
);
9193

tests/Feature/Select2Test.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,64 @@ public function it_can_render_a_select2_ajax_element()
114114
->seeElement('option[value=""]')
115115
->seeElement('option[value="2"]:selected');
116116
}
117+
118+
/** @test */
119+
public function it_can_render_a_select2_element_with_custom_form_group_class_material_admin_26()
120+
{
121+
$this->setFrameworkMaterialAdmin26();
122+
123+
$post = [
124+
'author' => 2,
125+
];
126+
127+
$options = [
128+
'1' => 'Arushad',
129+
'2' => 'John',
130+
'3' => 'Amy',
131+
];
132+
133+
Route::get('select2-basic', function () use ($post, $options) {
134+
return view('select2-basic-form-group-class')
135+
->with('post', $post)
136+
->with('options', $options);
137+
})->middleware('web');
138+
139+
$this->visit('/select2-basic')
140+
->seeElement('div.custom-class')
141+
->seeElement('select.select2-basic[id="author"][data-allow-clear="true"][data-placeholder="Nothing Selected"]')
142+
->seeElement('option[value=""]')
143+
->seeElement('option[value="1"]')
144+
->seeElement('option[value="2"]:selected')
145+
->seeElement('option[value="3"]');
146+
}
147+
148+
/** @test */
149+
public function it_can_render_a_select2_element_with_custom_form_group_class_bootstrap_5()
150+
{
151+
$this->setFrameworkBootstrap5();
152+
153+
$post = [
154+
'author' => 2,
155+
];
156+
157+
$options = [
158+
'1' => 'Arushad',
159+
'2' => 'John',
160+
'3' => 'Amy',
161+
];
162+
163+
Route::get('select2-basic', function () use ($post, $options) {
164+
return view('select2-basic-form-group-class')
165+
->with('post', $post)
166+
->with('options', $options);
167+
})->middleware('web');
168+
169+
$this->visit('/select2-basic')
170+
->seeElement('div.custom-class')
171+
->seeElement('select.select2-basic[id="author"][data-allow-clear="true"][data-placeholder="Nothing Selected"]')
172+
->seeElement('option[value=""]')
173+
->seeElement('option[value="1"]')
174+
->seeElement('option[value="2"]:selected')
175+
->seeElement('option[value="3"]');
176+
}
117177
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<x-forms::form :model="$post">
2+
<x-forms::select2 name="author" :options="$options" formGroupClass='custom-class'/>
3+
<x-forms::submit>Submit</x-forms::submit>
4+
</x-forms::form>

0 commit comments

Comments
 (0)