InputControl: Respect prop value if modified during onChange callback#76399
InputControl: Respect prop value if modified during onChange callback#76399
Conversation
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +10 B (0%) Total Size: 6.89 MB
ℹ️ View Unchanged
|
|
I'm investigating the test failure. Based on the test behavior, it makes sense that the invalid value would not be affected until loss of focus, but then this seems to me the purpose of |
|
Flaky tests detected in 489c4bd. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22971836094
|
So it might be right that For example, see how gutenberg/packages/components/src/number-control/index.tsx Lines 238 to 239 in 0086dd2 This worked previously because it was always based on the draft value which comes from Ultimately, this feels like it's an issue with how |
|
Okay, after testing this in the browser and seeing that the behavior asserted in the tests was the behavior I was seeing in the browser, I discovered that updating the test to use Separately, it's still true that The fact that I'll mark this as ready for review, but it's not quite as urgent to land given that #76400 now includes a solution that doesn't directly rely on this fix. |
|
The failing test in ColorPicker is another example of a knock-on effect 😕 Likely due to timing of internal debouncing. It might be back to the drawing board for how best to approach this problem in a way that retroactively handles all the components that depend on the current behavior. |
What?
Related to: #75530
Fixes an issue where
InputControlmay become stuck in a stale draft state if the controlled input value prop is changed during theonChangecallback, when used in combination withisPressEnterToChange.Why?
The
DateTimePickercomponent time component usesInputControlas a controlled input and syncs its value to state on change. As of #76400 (and prior to #73887, i.e. WordPress 6.9), this change handler may result in a date that is different than the original value entered in the field. Without these changes, the updated state value (and consequently controlled prop value) would not be accounted for in the change handling, meaning that the displayed value of the field may be out of sync with the the internal value representation.calendar-6.9.mov
How?
From my understanding of how this behavior was introduced in #40518, the idea is to allow an incoming prop value to take precedence over whatever value is "drafted" in the
isPressEnterToChangemode. The sequence of events when the value is manipulated during a change callback results in a desync that causes the draft to not reset when receiving the new prop value. Instead of comparing to the a copy of the last prop value (which may not be accurate), compare to the latest draft value directly.Testing Instructions
Repeat Testing Instructions from #40518
Verify regression tests pass:
npm run test:unit packages/components/src/input-control/test/index.jsOptionally, rebase this branch on top of
fix/day-picker-invalid-dayand observe that the interaction shown in the screen recording above correctly results in a date selection of February 28, 2026, reflected in both the input field and calendar.