Skip to content

Commit 8080709

Browse files
committed
Update the constructors to support extra attributes
1 parent 1beec7e commit 8080709

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

packages/framework/src/Framework/Features/Navigation/NavigationItem.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ class NavigationItem implements Stringable
3232
* @param \Hyde\Support\Models\Route|string<\Hyde\Support\Models\RouteKey>|string $destination Route instance or route key, or an external URI.
3333
* @param string|null $label If not provided, Hyde will try to get it from the route's connected page, or from the URL.
3434
* @param int|null $priority If not provided, Hyde will try to get it from the route or the default priority of 500.
35+
* @param array<string, scalar> $attributes Additional attributes for the navigation item.
3536
*/
36-
public function __construct(Route|string $destination, ?string $label = null, ?int $priority = null)
37+
public function __construct(Route|string $destination, ?string $label = null, ?int $priority = null, array $attributes = [])
3738
{
38-
[$this->destination, $this->label, $this->priority] = self::make($destination, $label, $priority);
39+
[$this->destination, $this->label, $this->priority, $this->attributes] = self::make($destination, $label, $priority, $attributes);
3940
}
4041

4142
/**
@@ -44,10 +45,11 @@ public function __construct(Route|string $destination, ?string $label = null, ?i
4445
* @param \Hyde\Support\Models\Route|string<\Hyde\Support\Models\RouteKey>|string $destination Route instance or route key, or an external URI.
4546
* @param string|null $label If not provided, Hyde will try to get it from the route's connected page, or from the URL.
4647
* @param int|null $priority If not provided, Hyde will try to get it from the route or the default priority of 500.
48+
* @param array<string, scalar> $attributes Additional attributes for the navigation item.
4749
*/
48-
public static function create(Route|string $destination, ?string $label = null, ?int $priority = null): static
50+
public static function create(Route|string $destination, ?string $label = null, ?int $priority = null, array $attributes = []): static
4951
{
50-
return new static(...self::make($destination, $label, $priority));
52+
return new static(...self::make($destination, $label, $priority, $attributes));
5153
}
5254

5355
/**

packages/framework/tests/Unit/NavigationItemTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,4 +325,16 @@ public function testIsCurrentIsNullSafe()
325325
{
326326
$this->assertFalse(NavigationItem::create('foo', 'bar')->isActive());
327327
}
328+
329+
public function testConstructWithAttributes()
330+
{
331+
$item = new NavigationItem('foo', 'Test', 500, ['class' => 'active']);
332+
$this->assertSame(['class' => 'active'], $item->getExtraAttributes());
333+
}
334+
335+
public function testCreateWithAttributes()
336+
{
337+
$item = NavigationItem::create('foo', 'Test', 500, ['class' => 'active']);
338+
$this->assertSame(['class' => 'active'], $item->getExtraAttributes());
339+
}
328340
}

0 commit comments

Comments
 (0)