File tree Expand file tree Collapse file tree 5 files changed +41
-1
lines changed
Expand file tree Collapse file tree 5 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ public function __construct(
1919
2020 public function apply (Element $ element ): Element
2121 {
22- if (! $ element instanceof ViewComponentElement) {
22+ if (
23+ ! $ element instanceof ViewComponentElement
24+ && ! $ element instanceof PhpDataElement
25+ ) {
2326 return $ element ;
2427 }
2528
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ public function __construct(
1919 ) {
2020 }
2121
22+ public function getAttribute (string $ name ): string |null
23+ {
24+ return $ this ->wrappingElement ->getAttribute ($ name );
25+ }
26+
2227 public function compile (): string
2328 {
2429 $ name = ltrim ($ this ->name , ': ' );
Original file line number Diff line number Diff line change 1+ <x-component name =" x-view-component-with-multiple-attributes" >
2+ <div class = " a" >
3+ { { $a } }
4+ </div >
5+ <div class = " b" >
6+ { { $b } }
7+ </div >
8+ </x-component >
Original file line number Diff line number Diff line change @@ -372,4 +372,24 @@ public function test_render_element_with_attribute_with_dash(): void
372372 $ html ,
373373 );
374374 }
375+
376+ public function test_view_component_with_multiple_attributes (): void
377+ {
378+ $ expected = '<div class="a">
379+ a </div>
380+ <div class="b">
381+ b </div> ' ;
382+
383+ $ html = $ this ->render (view ('<x-view-component-with-multiple-attributes a="a" b="b"></x-view-component-with-multiple-attributes> ' ));
384+ $ this ->assertStringEqualsStringIgnoringLineEndings ($ expected , $ html );
385+
386+ $ html = $ this ->render (view ('<x-view-component-with-multiple-attributes a="a" :b=" \'b \'"></x-view-component-with-multiple-attributes> ' ));
387+ $ this ->assertStringEqualsStringIgnoringLineEndings ($ expected , $ html );
388+
389+ $ html = $ this ->render (view ('<x-view-component-with-multiple-attributes :a=" \'a \'" :b=" \'b \'"></x-view-component-with-multiple-attributes> ' ));
390+ $ this ->assertStringEqualsStringIgnoringLineEndings ($ expected , $ html );
391+
392+ $ html = $ this ->render (view ('<x-view-component-with-multiple-attributes :a=" \'a \'" b="b"></x-view-component-with-multiple-attributes> ' ));
393+ $ this ->assertStringEqualsStringIgnoringLineEndings ($ expected , $ html );
394+ }
375395}
Original file line number Diff line number Diff line change @@ -61,9 +61,13 @@ public function test_nested_components(): void
6161 $ this ->assertStringEqualsStringIgnoringLineEndings (
6262 expected: <<<'HTML'
6363 <form action="#" method="post"><div><div><label for="a">a</label><input type="number" name="a" id="a" value></input></div>
64+
65+
6466 </div>
6567 <div><label for="b">b</label><input type="text" name="b" id="b" value></input></div>
6668
69+
70+
6771 </form>
6872 HTML,
6973 actual: $ this ->render (view (
You can’t perform that action at this time.
0 commit comments