Skip to content

Commit d02594f

Browse files
committed
fix(material/autocomplete): prevent outside clicks from going to other overlays
Adds a subscription to the outside click stream of the autocomplete overlay so that the events don't propagate to other overlays which may close the autocomplete prematurely. Fixes #25238.
1 parent a26b192 commit d02594f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

integration/harness-e2e-cli/e2e/radio-harness.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@ describe('app test', () => {
77
let loader: HarnessLoader;
88

99
beforeEach(async () => {
10+
console.log('starting');
1011
const driver = await configureDriver();
1112

1213
await driver.get('http://localhost:4200');
14+
console.log('loaded');
1315

1416
loader = SeleniumWebDriverHarnessEnvironment.loader(driver);
1517
});
1618

1719
it('should work', async () => {
20+
console.log('test start');
1821
const group = await loader.getHarness(MatRadioGroupHarness);
22+
console.log('group loaded');
1923

2024
expect(group).toBeDefined();
2125
expect(await group.getCheckedValue()).toBe(null);
26+
console.log('initial value');
2227

2328
const buttons = await group.getRadioButtons();
29+
console.log('fetched buttons');
2430
await buttons[1].check();
31+
console.log('checked');
2532

2633
expect(await group.getCheckedValue()).toBe('second');
34+
console.log('asserted');
2735
});
2836
});

src/material/autocomplete/autocomplete-trigger.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@ export abstract class _MatAutocompleteTriggerBase
836836
event.preventDefault();
837837
}
838838
});
839+
840+
// Subscribe to the pointer events stream so that it doesn't get picked up by other overlays.
841+
// TODO(crisbeto): we should switch `_getOutsideClickStream` eventually to use this stream,
842+
// but the behvior isn't exactly the same and it ends up breaking some internal tests.
843+
overlayRef.outsidePointerEvents().subscribe();
839844
}
840845
}
841846

0 commit comments

Comments
 (0)