fix(ui): refine mobile sidebar layout (#1100)
This commit is contained in:
@@ -228,7 +228,7 @@
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
@media (width <= 991px) {
|
||||
@media (width <= 767px) {
|
||||
.command-palette-shell {
|
||||
width: 100vw;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import { IconDisplayComponent } from '../../shared/components/icon-display/icon-
|
||||
import { PaletteItem } from './command-palette.model';
|
||||
import { CommandPaletteService } from './command-palette.service';
|
||||
|
||||
const MOBILE_MEDIA_QUERY = '(max-width: 991px)';
|
||||
const MOBILE_MEDIA_QUERY = '(max-width: 767px)';
|
||||
const MOBILE_TOPBAR_HEIGHT = '3.5rem';
|
||||
|
||||
@Component({
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
type="button"
|
||||
class="menu-item-link"
|
||||
[pTooltip]="currentItem.label"
|
||||
[tooltipDisabled]="!layoutService.sidebarCollapsed()"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
(click)="runAction($event)"
|
||||
>
|
||||
@@ -33,7 +33,7 @@
|
||||
[attr.aria-current]="isRouteActive() ? 'page' : null"
|
||||
[routerLink]="currentItem.routerLink"
|
||||
[pTooltip]="currentItem.label"
|
||||
[tooltipDisabled]="!layoutService.sidebarCollapsed()"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
tabindex="0"
|
||||
>
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 991px) {
|
||||
@media (width <= 767px) {
|
||||
.expand-icon-button {
|
||||
opacity: 1;
|
||||
width: 2rem;
|
||||
|
||||
@@ -11,6 +11,7 @@ describe('AppMenuSectionComponent', () => {
|
||||
|
||||
const layoutService = {
|
||||
sidebarCollapsed: signal(false),
|
||||
isDesktop: signal(true),
|
||||
sidebarExpandedState: signal<Readonly<Record<string, boolean>>>({}),
|
||||
isSidebarExpanded: vi.fn((key: string, defaultExpanded: boolean) => {
|
||||
const value = layoutService.sidebarExpandedState()[key];
|
||||
@@ -37,6 +38,8 @@ describe('AppMenuSectionComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
|
||||
layoutService.sidebarExpandedState.set({});
|
||||
layoutService.sidebarCollapsed.set(false);
|
||||
layoutService.isDesktop.set(true);
|
||||
layoutService.isSidebarExpanded.mockClear();
|
||||
layoutService.setSidebarExpanded.mockClear();
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ export class AppMenuSectionComponent {
|
||||
}
|
||||
|
||||
get submenuVisible(): boolean {
|
||||
return this.layoutService.sidebarCollapsed() || this.expanded;
|
||||
return (this.layoutService.isDesktop() && this.layoutService.sidebarCollapsed()) || this.expanded;
|
||||
}
|
||||
|
||||
toggleExpand(): void {
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
type="button"
|
||||
class="sidebar-action-link sidebar-search-button"
|
||||
[pTooltip]="t('search')"
|
||||
[tooltipDisabled]="!layoutService.sidebarCollapsed()"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
(click)="openSearch()"
|
||||
>
|
||||
@@ -133,7 +133,7 @@
|
||||
[attr.aria-label]="t('profile')"
|
||||
aria-haspopup="menu"
|
||||
[pTooltip]="user.name || user.username"
|
||||
[tooltipDisabled]="!layoutService.sidebarCollapsed()"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
(click)="openSidebarOverlay($event, userMenu, 'below')"
|
||||
>
|
||||
@@ -152,7 +152,7 @@
|
||||
[attr.aria-label]="layoutService.sidebarCollapsed() ? t('expandSidebar') : t('collapseSidebar')"
|
||||
[attr.aria-expanded]="!layoutService.sidebarCollapsed()"
|
||||
[pTooltip]="layoutService.sidebarCollapsed() ? t('expandSidebar') : t('collapseSidebar')"
|
||||
[tooltipDisabled]="!layoutService.sidebarCollapsed()"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
(click)="layoutService.toggleSidebarCollapsed()"
|
||||
>
|
||||
@@ -195,7 +195,7 @@
|
||||
[attr.aria-label]="layoutService.sidebarCollapsed() ? t('expandSidebar') : t('collapseSidebar')"
|
||||
[attr.aria-expanded]="!layoutService.sidebarCollapsed()"
|
||||
[pTooltip]="layoutService.sidebarCollapsed() ? t('expandSidebar') : t('collapseSidebar')"
|
||||
[tooltipDisabled]="!layoutService.sidebarCollapsed()"
|
||||
[tooltipDisabled]="!layoutService.desktopSidebarCollapsed()"
|
||||
tooltipPosition="right"
|
||||
(click)="layoutService.toggleSidebarCollapsed()"
|
||||
>
|
||||
|
||||
@@ -351,7 +351,7 @@
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
@media (width <= 991px) {
|
||||
@media (width <= 767px) {
|
||||
.sidebar-header {
|
||||
align-items: flex-start;
|
||||
margin-bottom: var(--space-3);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { signal, WritableSignal } from '@angular/core';
|
||||
import { computed, signal, WritableSignal } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
@@ -52,9 +52,12 @@ describe('AppMenuComponent', () => {
|
||||
let component: AppMenuComponent;
|
||||
let commandPaletteService: { open: ReturnType<typeof vi.fn> };
|
||||
let currentUser: WritableSignal<TestUser | null>;
|
||||
const sidebarCollapsed = signal(false);
|
||||
const isDesktop = signal(true);
|
||||
const layoutService = {
|
||||
sidebarCollapsed: signal(false),
|
||||
isDesktop: signal(true),
|
||||
sidebarCollapsed,
|
||||
isDesktop,
|
||||
desktopSidebarCollapsed: computed(() => isDesktop() && sidebarCollapsed()),
|
||||
librarySort: signal({ field: 'name', order: 'desc' }),
|
||||
shelfSort: signal({ field: 'name', order: 'asc' }),
|
||||
magicShelfSort: signal({ field: 'name', order: 'asc' }),
|
||||
|
||||
@@ -215,7 +215,7 @@ export class AppMenuComponent {
|
||||
|
||||
// `above` collapses to `below` when the sidebar is narrow, because the
|
||||
// anchored left offset assumes an expanded footer row.
|
||||
const anchorAbove = anchor.placement === 'above' && !this.layoutService.sidebarCollapsed();
|
||||
const anchorAbove = anchor.placement === 'above' && !this.layoutService.desktopSidebarCollapsed();
|
||||
if (anchorAbove) {
|
||||
const bottom = Math.max(window.innerHeight - rect.top + 8, 8);
|
||||
panel.style.setProperty('--sidebar-popover-bottom', `${bottom}px`);
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 991px) {
|
||||
@media (width <= 767px) {
|
||||
.mobile-topbar {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { DestroyRef, effect, inject, Injectable, signal, WritableSignal } from '@angular/core';
|
||||
import { computed, DestroyRef, effect, inject, Injectable, signal, WritableSignal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { filter } from 'rxjs';
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
export const SIDEBAR_MIN_WIDTH = 175;
|
||||
export const SIDEBAR_MAX_WIDTH = 400;
|
||||
export const SIDEBAR_DEFAULT_WIDTH = 225;
|
||||
const DESKTOP_MIN_WIDTH = 768;
|
||||
const SIDEBAR_EXPANDED_STATE_KEY = 'sidebarExpandedState';
|
||||
const SIDEBAR_TRANSITION_MS = 220;
|
||||
|
||||
@@ -51,6 +52,7 @@ export class LayoutService {
|
||||
readonly sidebarCollapsed = signal(this.localStorage.get<boolean>('sidebarCollapsed') ?? false);
|
||||
readonly sidebarWidth = signal(this.clampSidebarWidth(this.localStorage.get<number>('sidebarWidth') ?? SIDEBAR_DEFAULT_WIDTH));
|
||||
readonly isDesktop = signal(this.computeIsDesktop());
|
||||
readonly desktopSidebarCollapsed = computed(() => this.isDesktop() && this.sidebarCollapsed());
|
||||
readonly sidebarExpandedState = signal<Readonly<Record<string, boolean>>>(
|
||||
readBooleanRecord(this.localStorage, SIDEBAR_EXPANDED_STATE_KEY)
|
||||
);
|
||||
@@ -147,7 +149,7 @@ export class LayoutService {
|
||||
}
|
||||
|
||||
private computeIsDesktop(): boolean {
|
||||
return (this.document.defaultView?.innerWidth ?? 992) > 991;
|
||||
return (this.document.defaultView?.innerWidth ?? DESKTOP_MIN_WIDTH) >= DESKTOP_MIN_WIDTH;
|
||||
}
|
||||
|
||||
private readonly onResize = (): void => {
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media (width <= 991px) {
|
||||
@media (width <= 767px) {
|
||||
.layout-sidebar-resize-handle {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
@media (width >= 992px) {
|
||||
@media (width >= 768px) {
|
||||
.layout-wrapper {
|
||||
&.layout-sidebar-hidden {
|
||||
grid-template-columns: 0 minmax(0, 1fr);
|
||||
@@ -16,7 +16,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@media (width <= 991px) {
|
||||
@media (width <= 767px) {
|
||||
.blocked-scroll {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user