File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -214,7 +214,7 @@ public function withAttributes(array $attributes)
214
214
{
215
215
$ this ->attributes = $ this ->attributes ?: new ComponentAttributeBag ;
216
216
217
- $ this ->attributes -> setAttributes ($ attributes );
217
+ $ this ->attributes = $ this -> attributes -> merge ($ attributes );
218
218
219
219
return $ this ;
220
220
}
Original file line number Diff line number Diff line change @@ -45,6 +45,17 @@ public function testPublicMethodsWithNoArgsAreEagerlyInvokedAndNotCached()
45
45
$ component ->data ();
46
46
$ this ->assertEquals (3 , $ component ->counter );
47
47
}
48
+
49
+ public function testAttributesAreMergedNotOverwritten ()
50
+ {
51
+ $ component = new TestDefaultAttributesComponent ;
52
+
53
+ $ this ->assertEquals ('text-red-500 ' , $ component ->attributes ->get ('class ' ));
54
+
55
+ $ component ->withAttributes (['class ' => 'bg-blue-100 ' ]);
56
+
57
+ $ this ->assertEquals ('bg-blue-100 text-red-500 ' , $ component ->attributes ->get ('class ' ));
58
+ }
48
59
}
49
60
50
61
class TestViewComponent extends Component
@@ -99,3 +110,16 @@ private function privateHello()
99
110
$ this ->counter ++;
100
111
}
101
112
}
113
+
114
+ class TestDefaultAttributesComponent extends Component
115
+ {
116
+ public function __construct ()
117
+ {
118
+ $ this ->withAttributes (['class ' => 'text-red-500 ' ]);
119
+ }
120
+
121
+ public function render ()
122
+ {
123
+ return $ this ->attributes ->get ('id ' );
124
+ }
125
+ }
You can’t perform that action at this time.
0 commit comments