-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1606 from hydephp/clean-up-navigation-view-markup
[2.x] Clean up navigation view markup
- Loading branch information
Showing
7 changed files
with
124 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
packages/framework/resources/views/components/navigation/navigation-link.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<a href="{{ $item }}" {!! $item->isActive() ? 'aria-current="page"' : '' !!} @class([ | ||
'block my-2 md:my-0 md:inline-block py-1 text-gray-700 hover:text-gray-900 dark:text-gray-100', | ||
'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> | ||
<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() | ||
])->merge([ | ||
'aria-current' => $item->isActive() ? 'page' : false, | ||
]) }}>{{ $item->getLabel() }}</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
packages/framework/tests/Unit/Views/SidebarItemsViewTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hyde\Framework\Testing\Unit\Views; | ||
|
||
use Hyde\Hyde; | ||
use Hyde\Testing\TestCase; | ||
use Hyde\Support\Models\Route; | ||
use Hyde\Testing\TestsBladeViews; | ||
use Hyde\Pages\DocumentationPage; | ||
use Hyde\Testing\Support\TestView; | ||
use Hyde\Framework\Features\Navigation\DocumentationSidebar; | ||
use Hyde\Framework\Features\Navigation\NavigationMenuGenerator; | ||
|
||
/** | ||
* @see resources/views/components/docs/sidebar-items.blade.php | ||
*/ | ||
class SidebarItemsViewTest extends TestCase | ||
{ | ||
use TestsBladeViews; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->mockRoute(); | ||
} | ||
|
||
protected function testView(): TestView | ||
{ | ||
Hyde::routes()->addRoute(new Route(new DocumentationPage('foo'))); | ||
Hyde::routes()->addRoute(new Route(new DocumentationPage('bar'))); | ||
Hyde::routes()->addRoute(new Route(new DocumentationPage('baz'))); | ||
|
||
return $this->view(view('hyde::components.docs.sidebar-items', [ | ||
'sidebar' => NavigationMenuGenerator::handle(DocumentationSidebar::class), | ||
])); | ||
} | ||
|
||
public function testComponentRenders() | ||
{ | ||
$this->testView()->assertHasElement('#sidebar-items')->assertSeeTimes('listitem', 3); | ||
} | ||
|
||
public function testViewDoesNotContainActiveStateWhenNoPageIsActive() | ||
{ | ||
$this->testView() | ||
->assertDontSee('active') | ||
->assertDontSee('Table of contents') | ||
->assertDoesNotHaveAttribute('aria-current'); | ||
} | ||
|
||
public function testViewContainsActiveStateWhenPageIsActive() | ||
{ | ||
$this->mockCurrentPage('docs/foo'); | ||
$this->mockPage(new DocumentationPage('foo')); | ||
|
||
$this->testView() | ||
->assertSeeOnce('active') | ||
->assertSeeOnce('Table of contents') | ||
->assertHasAttribute('aria-current') | ||
->assertAttributeIs('aria-current="true"'); | ||
} | ||
|
||
public function testTypeAnnotationIsNotPresentInHtml() | ||
{ | ||
$this->testView()->assertDontSee('@var')->assertDontSee('$group'); | ||
} | ||
} |