Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: (CXSPA-944) - Repeated page title fix #19035

Merged
merged 11 commits into from
Aug 19, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,12 @@ export interface FeatureTogglesInterface {
*/
a11yLinkBtnsToTertiaryBtns?: boolean;

/**
* Aria-live inside the 'BreadcrumbComponent' will be toggled based on the active element.
* This removes the repeated announcement of the page title.
*/
a11yRepeatedPageTitleFix?: boolean;

/**
* In OCC cart requests, it puts parameters of a cart name and cart description
* into a request body, instead of query params.
Expand Down Expand Up @@ -454,6 +460,7 @@ export const defaultFeatureToggles: Required<FeatureTogglesInterface> = {
a11yFormErrorMuteIcon: false,
a11yCxMessageFocus: false,
a11yLinkBtnsToTertiaryBtns: false,
a11yRepeatedPageTitleFix: false,
occCartNameAndDescriptionInHttpRequestBody: false,
cmsBottomHeaderSlotUsingFlexStyles: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ if (environment.cpq) {
a11yCxMessageFocus: true,
occCartNameAndDescriptionInHttpRequestBody: true,
a11yLinkBtnsToTertiaryBtns: true,
a11yRepeatedPageTitleFix: true,
cmsBottomHeaderSlotUsingFlexStyles: true,
};
return appFeatureToggles;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

<!-- TODO: Remove feature flag next major release -->
<ng-container *cxFeature="'a11yPreventSRFocusOnHiddenElements'">
<h1 aria-live="polite" aria-atomic="true">{{ title$ | async }}</h1>
<h1 [attr.aria-live]="(ariaLive$ | async) ? 'polite' : null">
{{ title$ | async }}
</h1>
</ng-container>
<ng-container *cxFeature="'!a11yPreventSRFocusOnHiddenElements'">
<!-- Hidden page title for Screen Reader initialized after view to avoid old values -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
inject,
OnInit,
} from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import {
CmsBreadcrumbsComponent,
FeatureConfigService,
PageMetaService,
TranslationService,
useFeatureStyles,
} from '@spartacus/core';
import { combineLatest, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { combineLatest, Observable, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';
import { CmsComponentData } from '../../../cms-structure/page/model/cms-component-data';
import { PageTitleComponent } from '../page-header/page-title.component';

Expand All @@ -24,6 +31,20 @@ import { PageTitleComponent } from '../page-header/page-title.component';
export class BreadcrumbComponent extends PageTitleComponent implements OnInit {
crumbs$: Observable<any[]>;

protected router = inject(Router);
private featureConfigService = inject(FeatureConfigService);

ariaLive$: Observable<boolean> = this.featureConfigService.isEnabled(
'a11yRepeatedPageTitleFix'
)
? this.router.events.pipe(
filter((e) => e instanceof NavigationEnd),
map(() => {
return document.activeElement !== document.body;
})
)
: of(true);

constructor(
public component: CmsComponentData<CmsBreadcrumbsComponent>,
protected pageMetaService: PageMetaService,
Expand Down
Loading