Skip to content

Commit 9e8d631

Browse files
committed
refactor(material/timepicker): account for popover overlays
Updates the timepicker to account for the fact that the event bubbling will be different when we switch to using popovers.
1 parent 3a2a1bc commit 9e8d631

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

goldens/material/timepicker/index.api.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
4646
readonly disabled: Signal<boolean>;
4747
readonly disableRipple: InputSignalWithTransform<boolean, unknown>;
4848
protected _getAriaLabelledby(): string | null;
49+
// (undocumented)
50+
_getOverlayHost(): HTMLElement | undefined;
4951
protected _handleAnimationEnd(event: AnimationEvent): void;
5052
readonly interval: InputSignalWithTransform<number | null, number | string | null>;
5153
readonly isOpen: Signal<boolean>;

src/material/timepicker/timepicker-input.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import {MAT_INPUT_VALUE_ACCESSOR} from '../input';
4141
import {Subscription} from 'rxjs';
4242
import {DOWN_ARROW, ESCAPE, hasModifierKey, UP_ARROW} from '@angular/cdk/keycodes';
4343
import {validateAdapter} from './util';
44-
import {_getFocusedElementPierceShadowDom} from '@angular/cdk/platform';
44+
import {_getEventTarget, _getFocusedElementPierceShadowDom} from '@angular/cdk/platform';
4545

4646
/**
4747
* Input that can be used to enter time and connect to a `mat-timepicker`.
@@ -265,8 +265,15 @@ export class MatTimepickerInput<D>
265265
}
266266

267267
/** Handles clicks on the input or the containing form field. */
268-
private _handleClick = (): void => {
269-
if (!this.disabled() && this.openOnClick()) {
268+
private _handleClick = (event: MouseEvent): void => {
269+
if (this.disabled() || !this.openOnClick()) {
270+
return;
271+
}
272+
273+
const target = _getEventTarget(event) as Node | null;
274+
const overlayHost = this.timepicker()._getOverlayHost();
275+
276+
if (!target || !overlayHost || !overlayHost.contains(target)) {
270277
this.timepicker().open();
271278
}
272279
};

src/material/timepicker/timepicker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
312312
this._overlayRef?.dispose();
313313
}
314314

315+
_getOverlayHost() {
316+
return this._overlayRef?.hostElement;
317+
}
318+
315319
/** Selects a specific time value. */
316320
protected _selectValue(option: MatOption<D>) {
317321
this.close();

0 commit comments

Comments
 (0)