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 @@ -364,6 +364,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;

/**
* When enabled, styles for the `cx-bottom-header-slot` class will be applied. These styles are necessary to display
* customization buttons in the BottomHeaderSlot in SmartEdit.
Expand Down Expand Up @@ -429,5 +435,6 @@ export const defaultFeatureToggles: Required<FeatureTogglesInterface> = {
a11yDisabledCouponAndQuickOrderActionButtonsInsteadOfRequiredFields: false,
a11yFacetsDialogFocusHandling: false,
a11yLinkBtnsToTertiaryBtns: false,
a11yRepeatedPageTitleFix: false,
cmsBottomHeaderSlotUsingFlexStyles: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ if (environment.estimatedDeliveryDate) {
true,
a11yFacetsDialogFocusHandling: 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]="ariaLiveEnabled ? '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,23 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
inject,
OnDestroy,
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, Subscription } 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 @@ -21,8 +29,17 @@ import { PageTitleComponent } from '../page-header/page-title.component';
templateUrl: './breadcrumb.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class BreadcrumbComponent extends PageTitleComponent implements OnInit {
export class BreadcrumbComponent
extends PageTitleComponent
implements OnInit, OnDestroy
{
crumbs$: Observable<any[]>;
protected subscription = new Subscription();

private router = inject(Router);
Pio-Bar marked this conversation as resolved.
Show resolved Hide resolved
private featureConfigService = inject(FeatureConfigService);

ariaLiveEnabled = true;

constructor(
public component: CmsComponentData<CmsBreadcrumbsComponent>,
Expand All @@ -36,6 +53,19 @@ export class BreadcrumbComponent extends PageTitleComponent implements OnInit {
ngOnInit(): void {
super.ngOnInit();
this.setCrumbs();
if (this.featureConfigService.isEnabled('a11yRepeatedPageTitleFix')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore

this.subscription.add(
this.router.events
.pipe(filter((e) => e instanceof NavigationEnd))
.subscribe(() => {
if (document.activeElement === document.body) {
this.ariaLiveEnabled = false;
Pio-Bar marked this conversation as resolved.
Show resolved Hide resolved
return;
}
this.ariaLiveEnabled = true;
})
);
}
}

private setCrumbs(): void {
Expand All @@ -48,4 +78,8 @@ export class BreadcrumbComponent extends PageTitleComponent implements OnInit {
)
);
}

ngOnDestroy(): void {
this.subscription.unsubscribe();
}
}
Loading