-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Writing Flow: Avoid using state for tracking arrow key navigation #2894
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2894 +/- ##
==========================================
+ Coverage 33.92% 33.93% +0.01%
==========================================
Files 190 190
Lines 5695 5693 -2
Branches 999 999
==========================================
Hits 1932 1932
+ Misses 3183 3181 -2
Partials 580 580
Continue to review full report at Codecov.
|
@@ -17,13 +17,12 @@ const { UP, DOWN, LEFT, RIGHT } = keycodes; | |||
class WritingFlow extends Component { | |||
constructor() { | |||
super( ...arguments ); | |||
this.zones = []; |
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.
😅
some context here #2424 (comment) Basically, I first tried to only use So I decided to use |
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.
🚢 it
Related: https://github.com/WordPress/gutenberg/pull/2424/files#r142135955
This pull request seeks to refactor the WritingFlow component to eliminate state which could be set on arrow keypresses. Assigning state will incur a rerender, and for the intended usage, we do not need state to be reflected in the render result. Instead, for tracking the "should move" behavior, an instance property is sufficient and avoids any render.
Open questions:
I will need to look back through the old pull request, but at a glance I'm struggling to understand why we need to bind to both key down and key up, particularly because binding to key up causes a laggy feeling to the arrow movement.
Testing instructions:
Verify that there are no regressions in using arrow keys (left, right, up, down) to navigate from one input to the next / previous, e.g. between two paragraph blocks.