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