-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove forced focus of InputControl
on mousedown
#41118
base: trunk
Are you sure you want to change the base?
Conversation
* Update `RangeControl` to play nice with revised `InputControl` * Update `UnitControl` to play nice with revised `InputControl` * Restore controlled mode to `RangeControl` * Add missing ; * Add comment after deleting `onChange` * Update test of `RangeControl` to also test controlled mode * Remove separate onChange call from reset handling in `RangeControl` * Refine RESET logic of `InputControl` reducer * Simplify refined RESET logic of `InputControl` reducer * Restore initial position of `RangeControl` when without value * Differentiate state sync effect hooks by event existence * Add and use type `SecondaryReducer` * Cleanup legacy `event.perist()` * Simplify update from props in reducer Co-authored-by: Lena Morita <[email protected]> * Ensure event is cleared after drag actions * Avoid declaration of potential unused variable * Add more reset unit tests for `RangeControl` * Run `RangeControl` unit test in both controlled/uncontrolled modes * Make “keep invaid values” test async * Prevent interference of value entry in number input * Remove unused `floatClamp` function * Fix reset to `initialPosition` * Fix a couple tests for controlled `RangeControl` * Fix `RangeControl` reset * Ensure `InputControl`’s state syncing works after focus changes * Comment * Ignore NaN values in `useUnimpededRangedNumberEntry` * Refine use of event existence in state syncing effect hooks Co-authored-by: Marco Ciampini <[email protected]> Co-authored-by: Lena Morita <[email protected]>
Size Change: -56 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
@@ -41,18 +41,6 @@ describe( 'InputControl', () => { | |||
} ); | |||
} ); | |||
|
|||
describe( 'Ensurance of focus for number inputs', () => { | |||
it( 'should focus its input on mousedown events', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a silly question, but — shouldn't we keep this unit test?
Technically the code in this PR is not necessary, given change in #40518 — and therefore I would keep the unit tests as they are, and expect the to still pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test was added along with the code in #29305. I expected such a test to never fail #29305 (comment) because inputs are focused on mousedown
(except Firefox when mousedown
is on the spin buttons). Apparently that focus is not synchronous. So without the code this test fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thank you for the context!
I tried using user-event
and it seems to fix the issue:
describe( 'Ensurance of focus for number inputs', () => {
it( 'should focus its input on mousedown events', async () => {
const user = userEvent.setup( {
advanceTimers: jest.advanceTimersByTime,
} );
const spy = jest.fn();
render( <InputControl type="number" onFocus={ spy } /> );
const input = getInput();
await user.click( input );
expect( spy ).toHaveBeenCalledTimes( 1 );
} );
} );
5150ade
to
3ac6020
Compare
What?
Removes code obviated by #40518. For now this is based on the branch from that PR but once it lands I'll switch this to trunk.
Why?
It is no longer needed as it was only required (for Firefox) when
InputControl
had to be focused in order to update itself.How?
Removes the code and a unit test that was specific to it.
Testing Instructions
NumberControl
can be clicked to increment/decrement without causing the input to gain focus.InputControl
still behave as expected.Screen Recording
input-control-no-forced-focus.mp4