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: clear persisted focus on entering configuration #19413

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { productConfiguration } from '../../testing/configurator-test-data';
import { ConfiguratorTestUtils } from '../../testing/configurator-test-utils';
import { ConfiguratorAttributeHeaderComponent } from '../attribute/header/configurator-attribute-header.component';
import { ConfiguratorFormComponent } from './configurator-form.component';
import { KeyboardFocusService } from '@spartacus/storefront';

@Component({
selector: 'cx-configurator-group',
Expand Down Expand Up @@ -258,6 +259,7 @@ let component: ConfiguratorFormComponent;
let htmlElem: HTMLElement;
let configExpertModeService: ConfiguratorExpertModeService;
let hasConfigurationConflictsObservable: Observable<boolean> = EMPTY;
let keyboardFocusService: KeyboardFocusService;

describe('ConfigurationFormComponent', () => {
beforeEach(waitForAsync(() => {
Expand Down Expand Up @@ -347,6 +349,10 @@ describe('ConfigurationFormComponent', () => {
LaunchDialogService as Type<LaunchDialogService>
);
spyOn(launchDialogService, 'openDialogAndSubscribe').and.callThrough();
keyboardFocusService = TestBed.inject(
KeyboardFocusService as Type<KeyboardFocusService>
);
spyOn(keyboardFocusService, 'clear').and.callThrough();
});

describe('resolve issues navigation', () => {
Expand Down Expand Up @@ -421,6 +427,14 @@ describe('ConfigurationFormComponent', () => {
});
});

it('should reset persisted focus when UI is opened without resolve issue mode', () => {
routerStateObservable = mockRouterStateWithQueryParams({
resolveIssues: 'false',
});
createComponentWithData();
expect(keyboardFocusService.clear).toHaveBeenCalledTimes(1);
});

describe('Rendering', () => {
it('should render ghost view if no data is present', () => {
createComponentWithoutData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import {
Component,
OnDestroy,
OnInit,
inject,
} from '@angular/core';
import { GlobalMessageService, GlobalMessageType } from '@spartacus/core';
import {
ConfiguratorRouter,
ConfiguratorRouterExtractorService,
} from '@spartacus/product-configurator/common';
import { LAUNCH_CALLER, LaunchDialogService } from '@spartacus/storefront';
import {
LAUNCH_CALLER,
LaunchDialogService,
KeyboardFocusService,
} from '@spartacus/storefront';
import { Observable, Subscription } from 'rxjs';
import {
delay,
Expand All @@ -38,6 +43,7 @@ import { ConfiguratorExpertModeService } from '../../core/services/configurator-
export class ConfiguratorFormComponent implements OnInit, OnDestroy {
protected subscription = new Subscription();

protected focusService = inject(KeyboardFocusService);
routerData$: Observable<ConfiguratorRouter.Data> =
this.configRouterExtractorService.extractRouterData();

Expand Down Expand Up @@ -157,6 +163,9 @@ export class ConfiguratorFormComponent implements OnInit, OnDestroy {
);
}
});
} else {
// Clear persisted focus before entering the configurator UI
this.focusService.clear();
}

if (routingData.expMode) {
Expand Down