Skip to content

Conversation

Mr-KRAMA
Copy link
Contributor

@Mr-KRAMA Mr-KRAMA commented Oct 2, 2025

Problem:
The timepicker was firing the selected event before updating the form control value. This made it impossible to access the updated form value in event handlers, which is inconsistent with how the datepicker works.

What was happening:

timepicker.selected.subscribe(event => {
console.log('Event value:', event.value); // ✅ New time
console.log('Form control:', formControl.value); // ❌ Still old value
});

Copy
typescript
What happens now:

timepicker.selected.subscribe(event => {
console.log('Event value:', event.value); // ✅ New time
console.log('Form control:', formControl.value); // ✅ Updated value
});

Copy
typescript
Solution:

Modified the _selectValue method to emit the selected event after a microtask

This ensures the form control is updated before any event handlers run

Now behaves consistently with MatDatepicker

Testing:

Added test to verify form control value is available in selected event handler

All existing tests still pass

Fixes: #31950

@Mr-KRAMA Mr-KRAMA requested a review from a team as a code owner October 2, 2025 02:37
@Mr-KRAMA Mr-KRAMA requested review from adolgachev and wagnermaciel and removed request for a team October 2, 2025 02:37
@Mr-KRAMA Mr-KRAMA closed this Oct 2, 2025
@Mr-KRAMA Mr-KRAMA deleted the fix/timepicker-event-order branch October 3, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(timepicker): timepicker fire events before updating formControl value
1 participant