@@ -188,12 +188,6 @@ public function addSubMenu(string $text, \Closure $callback) : self
188
188
$ menu = $ builder ->build ();
189
189
$ menu ->setParent ($ this ->menu );
190
190
191
- //we apply the parent theme if nothing was changed
192
- //if no styles were changed in this sub-menu
193
- if (!$ menu ->getStyle ()->hasChangedFromDefaults ()) {
194
- $ menu ->setStyle ($ this ->menu ->getStyle ());
195
- }
196
-
197
191
$ this ->menu ->addItem ($ item = new MenuMenuItem (
198
192
$ text ,
199
193
$ menu ,
@@ -210,12 +204,6 @@ public function addSubMenuFromBuilder(string $text, CliMenuBuilder $builder) : s
210
204
$ menu = $ builder ->build ();
211
205
$ menu ->setParent ($ this ->menu );
212
206
213
- //we apply the parent theme if nothing was changed
214
- //if no styles were changed in this sub-menu
215
- if (!$ menu ->getStyle ()->hasChangedFromDefaults ()) {
216
- $ menu ->setStyle ($ this ->menu ->getStyle ());
217
- }
218
-
219
207
$ this ->menu ->addItem ($ item = new MenuMenuItem (
220
208
$ text ,
221
209
$ menu ,
@@ -556,6 +544,28 @@ public function build() : CliMenu
556
544
$ this ->style ->setDisplaysExtra ($ this ->itemsHaveExtra ($ this ->menu ->getItems ()));
557
545
}
558
546
547
+ if (!$ this ->subMenu ) {
548
+ $ this ->propagateStyles ($ this ->menu );
549
+ }
550
+
559
551
return $ this ->menu ;
560
552
}
553
+
554
+ /**
555
+ * Pass styles from current menu to sub-menu
556
+ * only if sub-menu style has not be customized
557
+ */
558
+ private function propagateStyles (CliMenu $ menu )
559
+ {
560
+ foreach ($ menu ->getItems () as $ item ) {
561
+ if ($ item instanceof MenuMenuItem) {
562
+ $ subMenu = $ item ->getSubMenu ();
563
+
564
+ !$ subMenu ->getStyle ()->hasChangedFromDefaults ()
565
+ && $ subMenu ->setStyle (clone $ menu ->getStyle ());
566
+
567
+ $ this ->propagateStyles ($ subMenu );
568
+ }
569
+ }
570
+ }
561
571
}
0 commit comments