Skip to content

Commit

Permalink
Refactor component to use attribute merging
Browse files Browse the repository at this point in the history
Create attribute bag in test setup
Update test to expect cleaner HTML output
  • Loading branch information
caendesilva committed Mar 13, 2024
1 parent c61eef9 commit 759c63a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<a href="{{ $item }}" {!! $item->isActive() ? 'aria-current="page"' : '' !!} @class([
<a href="{{ $item }}" {{ ($attributes->except('item')->class([
'navigation-link block my-2 md:my-0 md:inline-block py-1 text-gray-700 hover:text-gray-900 dark:text-gray-100',
'navigation-link-active border-l-4 border-indigo-500 md:border-none font-medium -ml-6 pl-5 md:ml-0 md:pl-0 bg-gray-100 dark:bg-gray-800 md:bg-transparent dark:md:bg-transparent' => $item->isActive()
])>{{ $item->getLabel() }}</a>
])->merge([
'aria-current' => ($item->isActive() ? 'page' : false),
])) }}>{{ $item->getLabel() }}</a>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hyde\Framework\Testing\Unit\Views;

use Hyde\Foundation\Facades\Routes;
use Illuminate\View\ComponentAttributeBag;
use Hyde\Framework\Features\Navigation\NavItem;
use Hyde\Testing\TestCase;

Expand All @@ -24,6 +25,7 @@ protected function render(?NavItem $item = null): string
{
return view('hyde::components.navigation.navigation-link', [
'item' => $item ?? NavItem::forLink('foo.html', 'Foo'),
'attributes' => new ComponentAttributeBag(),
])->render();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function testNavigationMenuWithRootPages()
$contents = $foo->compile();

$this->assertStringContainsString('<a href="foo.html" aria-current="page" class="', $contents);
$this->assertStringContainsString('<a href="bar.html" class="', $contents);
$this->assertStringContainsString('<a href="bar.html" class="', $contents);
}

public function testNavigationMenuWithDropdownPages()
Expand Down

0 comments on commit 759c63a

Please sign in to comment.