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)),
|
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 {
|
function closeMenus(): void {
|
||||||
navOpen = false;
|
navOpen = false;
|
||||||
profileOpen = false;
|
profileOpen = false;
|
||||||
@@ -164,27 +167,29 @@
|
|||||||
<span>{brand}</span>
|
<span>{brand}</span>
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
|
{#if hasNavItems}
|
||||||
{#each navItems as item}
|
<nav aria-label="Primary navigation" class="sc-nav" data-open={navOpen}>
|
||||||
{@const Icon = iconFor(item)}
|
{#each navItems as item}
|
||||||
<a
|
{@const Icon = iconFor(item)}
|
||||||
aria-current={isActive(item) ? 'page' : undefined}
|
<a
|
||||||
class="sc-nav-link"
|
aria-current={isActive(item) ? 'page' : undefined}
|
||||||
data-active={isActive(item)}
|
class="sc-nav-link"
|
||||||
href={item.href}
|
data-active={isActive(item)}
|
||||||
onclick={(event) => {
|
href={item.href}
|
||||||
if (onNavigate) {
|
onclick={(event) => {
|
||||||
event.preventDefault();
|
if (onNavigate) {
|
||||||
onNavigate(item);
|
event.preventDefault();
|
||||||
}
|
onNavigate(item);
|
||||||
closeMenus();
|
}
|
||||||
}}
|
closeMenus();
|
||||||
>
|
}}
|
||||||
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
|
>
|
||||||
{item.label}
|
<Icon aria-hidden="true" class="sc-nav-icon" size={16} strokeWidth={2} />
|
||||||
</a>
|
{item.label}
|
||||||
{/each}
|
</a>
|
||||||
</nav>
|
{/each}
|
||||||
|
</nav>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="sc-header-actions">
|
<div class="sc-header-actions">
|
||||||
{#if actions}{@render actions()}{/if}
|
{#if actions}{@render actions()}{/if}
|
||||||
@@ -273,14 +278,16 @@
|
|||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button
|
{#if hasNavItems}
|
||||||
aria-expanded={navOpen}
|
<button
|
||||||
aria-label={navOpen ? 'Close navigation menu' : 'Open navigation menu'}
|
aria-expanded={navOpen}
|
||||||
class="sc-icon-button sc-mobile-menu-button"
|
aria-label={navOpen ? 'Close navigation menu' : 'Open navigation menu'}
|
||||||
type="button"
|
class="sc-icon-button sc-mobile-menu-button"
|
||||||
onclick={() => (navOpen = !navOpen)}
|
type="button"
|
||||||
>
|
onclick={() => (navOpen = !navOpen)}
|
||||||
{navOpen ? '×' : '☰'}
|
>
|
||||||
</button>
|
{navOpen ? '×' : '☰'}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
Reference in new issue
Block a user