lavary/laravel-menu

Active class override

Opened this issue · 1 comments

if we set attr() method on menu item or link,it will clear the menu active class,to fix this problem,we shoud made some change to function attr() on Lavary\Menu\Item and Lavary\Menu\Link

we should add one line of code in function attr()

public function attr()
   {
       $args = func_get_args();

      
       if (isset($args[0]) && is_array($args[0])) {
           if(isset($args[0]["class"]) && isset($this->attributes["class"])){                
                $args[0]["class"] = Builder::formatGroupClass($args[0],$this->attributes);
           }
              
           $this->attributes = array_merge($this->attributes, $args[0]);
           

           return $this;
       } elseif (isset($args[0]) && isset($args[1])) {
           $this->attributes[$args[0]] = $args[1];

           return $this;
       } elseif (isset($args[0])) {
           return isset($this->attributes[$args[0]]) ? $this->attributes[$args[0]] : null;
       }
      
       
       return $this->attributes;
   }

like abouve I have added the code

if(isset($args[0]["class"]) && isset($this->attributes["class"])){                
                $args[0]["class"] = Builder::formatGroupClass($args[0],$this->attributes);
           }

I can see where you are going with it, I think it is a good idea. Someone could open a PR.