fix: hide navigation controls for a single nav item
Docker / Docker Build & Push (push) Successful in 3m51s
Docker / Docker Build & Push (push) Successful in 3m51s
This commit is contained in:
1 parent
4e9cb20971
commit
0d27c9a8d9
1 file changed
+37
-30
@@ -130,6 +130,9 @@
|
||||
Boolean(username && (onProfile || (showSettings && onSettings) || onAbout || aboutHref || onLogout)),
|
||||
);
|
||||
|
||||
// A lone nav item is just the app's home page, so it isn't worth a header tab (or a menu toggle).
|
||||
const hasNavItems = $derived(navItems.length > 1);
|
||||
|
||||
function closeMenus(): void {
|
||||
navOpen = false;
|
||||
profileOpen = false;
|
||||
@@ -164,27 +167,29 @@
|
||||
<span>{brand}</span>
|
||||
</a>
|
||||
|
||||
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
|
||||
{#each navItems as item}
|
||||
{@const Icon = iconFor(item)}
|
||||
<a
|
||||
aria-current={isActive(item) ? 'page' : undefined}
|
||||
class="sc-nav-link"
|
||||
data-active={isActive(item)}
|
||||
href={item.href}
|
||||
onclick={(event) => {
|
||||
if (onNavigate) {
|
||||
event.preventDefault();
|
||||
onNavigate(item);
|
||||
}
|
||||
closeMenus();
|
||||
}}
|
||||
>
|
||||
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
|
||||
{item.label}
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
{#if hasNavItems}
|
||||
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
|
||||
{#each navItems as item}
|
||||
{@const Icon = iconFor(item)}
|
||||
<a
|
||||
aria-current={isActive(item) ? 'page' : undefined}
|
||||
class="sc-nav-link"
|
||||
data-active={isActive(item)}
|
||||
href={item.href}
|
||||
onclick={(event) => {
|
||||
if (onNavigate) {
|
||||
event.preventDefault();
|
||||
onNavigate(item);
|
||||
}
|
||||
closeMenus();
|
||||
}}
|
||||
>
|
||||
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
|
||||
{item.label}
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
{/if}
|
||||
|
||||
<div class="sc-header-actions">
|
||||
{#if actions}{@render actions()}{/if}
|
||||
@@ -273,14 +278,16 @@
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<button
|
||||
aria-expanded={navOpen}
|
||||
aria-label={navOpen ? 'Close navigation menu' : 'Open navigation menu'}
|
||||
class="sc-icon-button sc-mobile-menu-button"
|
||||
type="button"
|
||||
onclick={() => (navOpen = !navOpen)}
|
||||
>
|
||||
{navOpen ? '×' : '☰'}
|
||||
</button>
|
||||
{#if hasNavItems}
|
||||
<button
|
||||
aria-expanded={navOpen}
|
||||
aria-label={navOpen ? 'Close navigation menu' : 'Open navigation menu'}
|
||||
class="sc-icon-button sc-mobile-menu-button"
|
||||
type="button"
|
||||
onclick={() => (navOpen = !navOpen)}
|
||||
>
|
||||
{navOpen ? '×' : '☰'}
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
</header>
|
||||
Reference in new issue
Block a user