Skip to content

Commit

Permalink
Merge branch 'develop' into revert-19321-chore/add-ver-desc-to-minor-…
Browse files Browse the repository at this point in the history
…release-pipeline
  • Loading branch information
rmch91 authored Dec 19, 2024
2 parents aedff18 + a8801dc commit 605bc37
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
QuickOrderFacade,
} from '@spartacus/cart/quick-order/root';
import {
FeatureConfigService,
FeaturesConfig,
GlobalMessageService,
GlobalMessageType,
Expand Down Expand Up @@ -64,6 +65,12 @@ class MockGlobalMessageService implements Partial<GlobalMessageService> {
): void {}
}

class MockFeatureConfigService {
isEnabled() {
return true;
}
}

@Component({
selector: 'cx-icon',
template: '',
Expand Down Expand Up @@ -101,6 +108,7 @@ describe('QuickOrderFormComponent', () => {
features: { level: '5.1' },
},
},
{ provide: FeatureConfigService, useClass: MockFeatureConfigService },
],
}).compileComponents();

Expand Down Expand Up @@ -214,6 +222,20 @@ describe('QuickOrderFormComponent', () => {
component.clear(ev as Event);
expect(ev.preventDefault).toHaveBeenCalled();
});

it('sets focus back to the input if results box was open', (done) => {
const inputSearch: HTMLElement = fixture.debugElement.query(
By.css('input')
).nativeElement;

component.open();
expect(inputSearch).not.toBe(getFocusedElement());
component.clear();
requestAnimationFrame(() => {
expect(inputSearch).toBe(getFocusedElement());
done();
});
});
});

it('should not change focus on focusNextChild if results list is empty', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ import {
ChangeDetectorRef,
Component,
ElementRef,
inject,
Input,
OnDestroy,
OnInit,
ViewChild,
} from '@angular/core';
import { UntypedFormControl, UntypedFormGroup } from '@angular/forms';
import { QuickOrderFacade } from '@spartacus/cart/quick-order/root';
import { Config, Product, WindowRef, useFeatureStyles } from '@spartacus/core';
import {
Config,
FeatureConfigService,
Product,
useFeatureStyles,
WindowRef,
} from '@spartacus/core';
import { ICON_TYPE } from '@spartacus/storefront';
import { Observable, Subscription } from 'rxjs';
import {
Expand Down Expand Up @@ -45,6 +52,7 @@ export class QuickOrderFormComponent implements OnInit, OnDestroy {

@ViewChild('quickOrderInput') quickOrderInput: ElementRef;

private featureConfigService = inject(FeatureConfigService);
protected subscription = new Subscription();
protected searchSubscription = new Subscription();

Expand Down Expand Up @@ -78,6 +86,15 @@ export class QuickOrderFormComponent implements OnInit, OnDestroy {

if (this.isResultsBoxOpen()) {
this.toggleBodyClass(SEARCH_BOX_ACTIVE_CLASS, false);
if (
this.featureConfigService.isEnabled(
'a11yQuickOrderSearchBoxRefocusOnClose'
)
) {
requestAnimationFrame(() => {
this.quickOrderInput.nativeElement.focus();
});
}
}

const product = this.form.get('product')?.value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,11 @@ export interface FeatureTogglesInterface {
*/
a11yDifferentiateFocusedAndSelected?: boolean;

/**
* When enabled the input element in `QuickOrderFormComponent' will regain its focus after the dropdown is closed.
*/
a11yQuickOrderSearchBoxRefocusOnClose?: boolean;

/**
* Adds a visible focus indicator for keyboard navigation in the `SearchBoxComponent` without affecting the visual state for mouse interactions.
* Affects: SearchBoxComponent
Expand Down Expand Up @@ -1047,6 +1052,7 @@ export const defaultFeatureToggles: Required<FeatureTogglesInterface> = {
a11ySearchboxAssistiveMessage: false,
updateConsentGivenInOnChanges: false,
a11yDifferentiateFocusedAndSelected: false,
a11yQuickOrderSearchBoxRefocusOnClose: false,
a11yKeyboardFocusInSearchBox: false,
a11yAddPaddingToCarouselPanel: false,
a11yHideConsentButtonWhenBannerVisible: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ if (environment.cpq) {
a11ySearchboxAssistiveMessage: true,
updateConsentGivenInOnChanges: true,
a11yDifferentiateFocusedAndSelected: true,
a11yQuickOrderSearchBoxRefocusOnClose: true,
a11yKeyboardFocusInSearchBox: true,
a11yAddPaddingToCarouselPanel: true,
a11yHideConsentButtonWhenBannerVisible: true,
Expand Down

0 comments on commit 605bc37

Please sign in to comment.