Skip to content

Commit 14e9ec7

Browse files
committedOct 4, 2024
fix(material/timepicker): always re-focus input
Fixes that nothing was happening if the user clicks on the toggle while the timepicker is open.
1 parent d3cbd48 commit 14e9ec7

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed
 

‎src/material/timepicker/timepicker.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -208,20 +208,25 @@ export class MatTimepicker<D> implements OnDestroy, MatOptionParentComponent {
208208

209209
/** Opens the timepicker. */
210210
open(): void {
211-
if (!this._input || this._isOpen()) {
211+
if (!this._input) {
212212
return;
213213
}
214214

215+
// Focus should already be on the input, but this call is in case the timepicker is opened
216+
// programmatically. We need to call this even if the timepicker is already open, because
217+
// the user might be clicking the toggle.
218+
this._input.focus();
219+
220+
if (this._isOpen()) {
221+
return;
222+
}
223+
224+
this._isOpen.set(true);
215225
this._generateOptions();
216226
const overlayRef = this._getOverlayRef();
217227
overlayRef.updateSize({width: this._input.getOverlayOrigin().nativeElement.offsetWidth});
218228
this._portal ??= new TemplatePortal(this._panelTemplate(), this._viewContainerRef);
219229
overlayRef.attach(this._portal);
220-
this._isOpen.set(true);
221-
222-
// Focus should already be on the input, but this call is
223-
// in case the timepicker is opened programmatically.
224-
this._input.focus();
225230
this._onOpenRender?.destroy();
226231
this._onOpenRender = afterNextRender(
227232
() => {

0 commit comments

Comments
 (0)
Please sign in to comment.