@@ -38,7 +38,7 @@ class MenuItem implements \Kfn\Menu\Contracts\MenuItem
3838 * @param array $param
3939 * @param array|object $attribute
4040 * @param int $sort
41- * @param string|null $activeName
41+ * @param string|array| null $activeName
4242 * @param array|null $activeParam
4343 * @param \Closure|bool $resolver
4444 */
@@ -49,7 +49,7 @@ public function __construct(
4949 readonly public array $ param = [],
5050 array |object $ attribute = [],
5151 readonly public int $ sort = 0 ,
52- readonly public string |null $ activeName = null ,
52+ readonly public string |array | null $ activeName = null ,
5353 readonly public array |null $ activeParam = null ,
5454 readonly public \Closure |bool $ resolver = true
5555 ) {
@@ -124,19 +124,22 @@ private function resolveHref(): void
124124 *
125125 * @return bool
126126 */
127- private function getActiveStatus (string |null $ name = '' , array $ params = []): bool
127+ private function getActiveStatus (string |array | null $ name = '' , array $ params = []): bool
128128 {
129- $ name = str ($ name )->trim ();
129+ $ name = collect ((array ) $ name )->flatMap (function ($ nm ) {
130+ $ nm = preg_replace ('/\s+|\h+/ ' , '' , $ nm );
131+ if (!empty ($ nm )) {
132+ return MenuType::ROUTE === $ this ->type ? [$ nm , $ nm .'.* ' ] : [$ nm , $ nm .'/* ' ];
133+ }
134+ });
130135 if ($ name ->isEmpty ()) {
131136 return false ;
132137 }
133138
134139 try {
135- $ name = $ name ->toString ();
136-
137140 return match ($ this ->type ) {
138- MenuType::ROUTE => $ this ->getActiveByRoute ($ name , $ params ),
139- MenuType::URL => $ this ->getActiveByUrl ($ name ),
141+ MenuType::ROUTE => $ this ->getActiveByRoute ($ name-> toArray () , $ params ),
142+ MenuType::URL => $ this ->getActiveByUrl ($ name-> toArray () ),
140143 default => false ,
141144 };
142145 } catch (Exception $ e ) {
@@ -146,14 +149,14 @@ private function getActiveStatus(string|null $name = '', array $params = []): bo
146149 return false ;
147150 }
148151
149- private function getActiveByUrl (string $ name ): bool
152+ private function getActiveByUrl (array $ names ): bool
150153 {
151- return request ()->is ($ name , "{ $ name } .* " );
154+ return request ()->is ($ names );
152155 }
153156
154- private function getActiveByRoute (string $ name , array $ params = []): bool
157+ private function getActiveByRoute (array $ names , array $ params = []): bool
155158 {
156- if (request ()->routeIs ($ name , "{ $ name } .* " )) {
159+ if (request ()->routeIs ($ names )) {
157160 if (empty ($ params )) {
158161 return true ;
159162 }
0 commit comments