File

projects/storefrontlib/cms-components/product/product-list/product-facet-navigation/active-facets/active-facets.component.ts

Description

Active facets render the applied facet values as a list of focusable buttons which can be used to remove the applied facet value.

Metadata

changeDetection ChangeDetectionStrategy.Default
selector cx-active-facets
templateUrl ./active-facets.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(facetService: FacetService)
Parameters :
Name Type Optional
facetService FacetService No

Inputs

closeIcon
Type : any
Default value : ICON_TYPE.CLOSE

Configurable icon which is used for the active facet close button

Methods

getFocusKey
getFocusKey(facetList: FacetList, facet: Breadcrumb)

The focus key is used to persist the focus on the facet when the DOM is being recreated. We only apply the focus key for the given active facet when there the original facets is not available. This happens for non multi-valued facets.

With this approach, the we keep the focus, either at the facet list or on the active facets.

Parameters :
Name Type Optional
facetList FacetList No
facet Breadcrumb No
Returns : any
getLinkParams
getLinkParams(facet: Breadcrumb)
Parameters :
Name Type Optional
facet Breadcrumb No
Returns : any

Properties

closeIcon
Default value : ICON_TYPE.CLOSE
Decorators :
@Input()

Configurable icon which is used for the active facet close button

facetList$
Type : Observable<FacetList>
Default value : this.facetService.facetList$

Active facets which are applied to the product results.

import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
import { Breadcrumb } from '@spartacus/core';
import { Observable } from 'rxjs';
import { ICON_TYPE } from '../../../../../cms-components/misc/icon/icon.model';
import { FacetList } from '../facet.model';
import { FacetService } from '../services/facet.service';

/**
 * Active facets render the applied facet values as a list of focusable buttons
 * which can be used to remove the applied facet value.
 */
@Component({
  selector: 'cx-active-facets',
  templateUrl: './active-facets.component.html',
  changeDetection: ChangeDetectionStrategy.Default,
})
export class ActiveFacetsComponent {
  /** Active facets which are applied to the product results. */
  facetList$: Observable<FacetList> = this.facetService.facetList$;

  /** Configurable icon which is used for the active facet close button */
  @Input() closeIcon = ICON_TYPE.CLOSE;

  constructor(protected facetService: FacetService) {}

  getLinkParams(facet: Breadcrumb) {
    return this.facetService.getLinkParams(facet.removeQuery?.query?.value);
  }

  /**
   * The focus key is used to persist the focus on the facet when the DOM is being
   * recreated. We only apply the focus key for the given _active_ facet when there
   * the original facets is not available. This happens for non multi-valued facets.
   *
   * With this approach, the we keep the focus, either at the facet list or on the
   * active facets.
   */
  getFocusKey(facetList: FacetList, facet: Breadcrumb) {
    return facetList.facets?.find((f) =>
      f.values?.find((val) => val.name === facet.facetValueName)
    )
      ? ''
      : facet.facetValueName;
  }
}
<ng-container *ngIf="facetList$ | async as facetList">
  <h4 *ngIf="facetList?.activeFacets?.length > 0">
    {{ 'productList.appliedFilter' | cxTranslate }}
  </h4>

  <a
    *ngFor="let facet of facetList?.activeFacets"
    routerLink="./"
    [queryParams]="getLinkParams(facet)"
    [cxFocus]="getFocusKey(facetList, facet)"
  >
    <span>{{ facet.facetValueName }}</span>
    <cx-icon aria-hidden="true" [type]="closeIcon"></cx-icon>
  </a>
</ng-container>
Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""