File
Implements
Metadata
| selector |
cx-storefront |
| templateUrl |
./storefront.component.html |
Index
Properties
|
|
|
Methods
|
|
|
HostBindings
|
|
|
HostListeners
|
|
|
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()
|
|
|
|
|
|
collapseMenuIfClickOutside
|
collapseMenuIfClickOutside(event: any)
|
|
|
Parameters :
| Name |
Type |
Optional |
| event |
any
|
No
|
|
|
handleEscape
|
handleEscape(event: KeyboardEvent)
|
Decorators :
@HostListener('keydown.escape', ['$event'])
|
|
|
Parameters :
| Name |
Type |
Optional |
| event |
KeyboardEvent
|
No
|
|
|
ngOnDestroy
|
ngOnDestroy()
|
|
|
|
|
|
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 with directive