Skip to content

Commit 31c8fc1

Browse files
crisbetoandrewseguin
authored andcommitted
build: fix autocomplete CI failure (#24226)
Fixes a couple of failures that made it through due to an old PR. (cherry picked from commit 63d4b73)
1 parent 402c07b commit 31c8fc1

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/material-experimental/mdc-autocomplete/autocomplete.spec.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,8 +1101,10 @@ describe('MDC-based MatAutocomplete', () => {
11011101

11021102
expect(trigger.panelOpen).toBe(true, 'Expected panel to remain open.');
11031103
expect(input.value).toBeFalsy('Expected input to remain blank.');
1104-
expect(ENTER_EVENT.defaultPrevented)
1105-
.toBe(false, 'Expected the default ENTER action not to have been prevented.');
1104+
expect(ENTER_EVENT.defaultPrevented).toBe(
1105+
false,
1106+
'Expected the default ENTER action not to have been prevented.',
1107+
);
11061108
}));
11071109

11081110
it('should fill the text field, not select an option, when SPACE is entered', () => {
@@ -2868,6 +2870,29 @@ describe('MDC-based MatAutocomplete', () => {
28682870
expect(event.option.value).toBe('Washington');
28692871
}));
28702872

2873+
it('should refocus the input after the selection event is emitted', fakeAsync(() => {
2874+
const events: string[] = [];
2875+
const fixture = createComponent(AutocompleteWithSelectEvent);
2876+
fixture.detectChanges();
2877+
const input = fixture.nativeElement.querySelector('input');
2878+
2879+
fixture.componentInstance.trigger.openPanel();
2880+
zone.simulateZoneExit();
2881+
fixture.detectChanges();
2882+
2883+
const options = overlayContainerElement.querySelectorAll(
2884+
'mat-option',
2885+
) as NodeListOf<HTMLElement>;
2886+
spyOn(input, 'focus').and.callFake(() => events.push('focus'));
2887+
fixture.componentInstance.optionSelected.and.callFake(() => events.push('select'));
2888+
2889+
options[1].click();
2890+
tick();
2891+
fixture.detectChanges();
2892+
2893+
expect(events).toEqual(['select', 'focus']);
2894+
}));
2895+
28712896
it('should emit an event when a newly-added option is selected', fakeAsync(() => {
28722897
let fixture = createComponent(AutocompleteWithSelectEvent);
28732898

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ export abstract class _MatAutocompleteTriggerBase
316316
if (options) {
317317
return options.changes.pipe(
318318
startWith(options),
319-
switchMap(() => merge(...options.map(option => option.onSelectionChange)))
319+
switchMap(() => merge(...options.map(option => option.onSelectionChange))),
320320
);
321321
}
322322

src/material/autocomplete/autocomplete.spec.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,8 +1097,10 @@ describe('MatAutocomplete', () => {
10971097

10981098
expect(trigger.panelOpen).toBe(true, 'Expected panel to remain open.');
10991099
expect(input.value).toBeFalsy('Expected input to remain blank.');
1100-
expect(ENTER_EVENT.defaultPrevented)
1101-
.toBe(false, 'Expected the default ENTER action not to have been prevented.');
1100+
expect(ENTER_EVENT.defaultPrevented).toBe(
1101+
false,
1102+
'Expected the default ENTER action not to have been prevented.',
1103+
);
11021104
}));
11031105

11041106
it('should fill the text field, not select an option, when SPACE is entered', () => {
@@ -2882,8 +2884,9 @@ describe('MatAutocomplete', () => {
28822884
zone.simulateZoneExit();
28832885
fixture.detectChanges();
28842886

2885-
const options =
2886-
overlayContainerElement.querySelectorAll('mat-option') as NodeListOf<HTMLElement>;
2887+
const options = overlayContainerElement.querySelectorAll(
2888+
'mat-option',
2889+
) as NodeListOf<HTMLElement>;
28872890
spyOn(input, 'focus').and.callFake(() => events.push('focus'));
28882891
fixture.componentInstance.optionSelected.and.callFake(() => events.push('select'));
28892892

0 commit comments

Comments
 (0)