File

projects/storefrontlib/layout/main/storefront.component.ts

Implements

OnInit OnDestroy

Metadata

selector cx-storefront
templateUrl ./storefront.component.html

Index

Properties
Methods
HostBindings
HostListeners

Constructor

constructor(hamburgerMenuService: HamburgerMenuService, routingService: RoutingService, elementRef: ElementRef, keyboardFocusService: KeyboardFocusService)
Parameters :
Name Type Optional
hamburgerMenuService HamburgerMenuService No
routingService RoutingService No
elementRef ElementRef<HTMLElement> No
keyboardFocusService KeyboardFocusService No

HostBindings

class.start-navigating
Type : any
class.stop-navigating
Type : any
tabindex
Type : string
Default value : '0'

HostListeners

keydown.escape
Arguments : '$event'
keydown.escape(event: KeyboardEvent)

Methods

collapseMenu
collapseMenu()
Returns : void
collapseMenuIfClickOutside
collapseMenuIfClickOutside(event: any)
Parameters :
Name Type Optional
event any No
Returns : void
handleEscape
handleEscape(event: KeyboardEvent)
Decorators :
@HostListener('keydown.escape', ['$event'])
Parameters :
Name Type Optional
event KeyboardEvent No
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

child
Type : SkipLinkComponent
Decorators :
@ViewChild(SkipLinkComponent)
isExpanded$
Type : Observable<boolean>
Default value : this.hamburgerMenuService.isExpanded
Private keyboardFocusConfig
Type : FocusConfig
Default value : { focusOnEscape: true, focusOnDoubleEscape: true, }
navigateSubscription
Type : Subscription
startNavigating
Decorators :
@HostBinding('class.start-navigating')
stopNavigating
Decorators :
@HostBinding('class.stop-navigating')
Readonly StorefrontOutlets
Default value : StorefrontOutlets
tabindex
Type : string
Default value : '0'
Decorators :
@HostBinding('tabindex')
import {
  Component,
  ElementRef,
  HostBinding,
  HostListener,
  OnDestroy,
  OnInit,
  ViewChild,
} from '@angular/core';
import { RoutingService } from '@spartacus/core';
import { Observable, Subscription } from 'rxjs';
import {
  FocusConfig,
  KeyboardFocusService,
} from '../a11y/keyboard-focus/index';
import { SkipLinkComponent } from '../a11y/skip-link/index';
import { HamburgerMenuService } from '../header/hamburger-menu/hamburger-menu.service';
import { StorefrontOutlets } from './storefront-outlets.model';

@Component({
  selector: 'cx-storefront',
  templateUrl: './storefront.component.html',
})
export class StorefrontComponent implements OnInit, OnDestroy {
  navigateSubscription: Subscription;
  isExpanded$: Observable<boolean> = this.hamburgerMenuService.isExpanded;

  readonly StorefrontOutlets = StorefrontOutlets;

  @HostBinding('class.start-navigating') startNavigating;
  @HostBinding('class.stop-navigating') stopNavigating;

  // required by esc focus
  @HostBinding('tabindex') tabindex = '0';

  @ViewChild(SkipLinkComponent) child: SkipLinkComponent;

  private keyboardFocusConfig: FocusConfig = {
    focusOnEscape: true,
    focusOnDoubleEscape: true,
  };

  @HostListener('keydown.escape', ['$event'])
  handleEscape(event: KeyboardEvent): void {
    this.keyboardFocusService.handleEscape(
      this.elementRef.nativeElement,
      this.keyboardFocusConfig,
      event
    );
  }

  constructor(
    private hamburgerMenuService: HamburgerMenuService,
    private routingService: RoutingService,
    protected elementRef: ElementRef<HTMLElement>,
    protected keyboardFocusService: KeyboardFocusService
  ) {}

  ngOnInit(): void {
    this.navigateSubscription = this.routingService
      .isNavigating()
      .subscribe((val) => {
        this.startNavigating = val === true;
        this.stopNavigating = val === false;
      });
  }

  collapseMenuIfClickOutside(event: any): void {
    const element = event.target;
    if (
      element.nodeName.toLowerCase() === 'header' &&
      element.className.includes('is-expanded')
    ) {
      this.collapseMenu();
    }
  }

  collapseMenu(): void {
    this.hamburgerMenuService.toggle(true);
  }

  ngOnDestroy(): void {
    if (this.navigateSubscription) {
      this.navigateSubscription.unsubscribe();
    }
  }
}
<ng-template [cxOutlet]="StorefrontOutlets.STOREFRONT" cxPageTemplateStyle>
  <ng-template cxOutlet="cx-header">
    <header
      cxSkipLink="cx-header"
      [cxFocus]="{ disableMouseFocus: true }"
      [class.is-expanded]="isExpanded$ | async"
      (keydown.escape)="collapseMenu()"
      (click)="collapseMenuIfClickOutside($event)"
    >
      <cx-page-layout section="header"></cx-page-layout>
      <cx-page-layout section="navigation"></cx-page-layout>
    </header>
    <cx-page-slot position="BottomHeaderSlot"></cx-page-slot>
    <cx-global-message
      aria-atomic="true"
      aria-live="assertive"
    ></cx-global-message>
  </ng-template>

  <main cxSkipLink="cx-main" [cxFocus]="{ disableMouseFocus: true }">
    <router-outlet></router-outlet>
  </main>

  <ng-template cxOutlet="cx-footer">
    <footer cxSkipLink="cx-footer" [cxFocus]="{ disableMouseFocus: true }">
      <cx-page-layout section="footer"></cx-page-layout>
    </footer>
  </ng-template>
</ng-template>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""