-
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 focus on multi-select stop #3253
Conversation
a8efc50
to
cf075fb
Compare
The problem is that WritingFlow only listens for key presses on the element, not globally. Should it maybe? cc @mcsf This is a problem in master too if you make a selection, then place the focus somewhere else and then try to expand the selection with shift+arrow keys. The visual selection is still there, but nothing will happen. I think either WritingFlow needs to listen for all key presses, or the selection needs to disappear if you click out of the editor area (e.g. in the inspector). |
Don't know about 1efd3cc, but that would fix it. Otherwise we need to move the focus somewhere inside writing flow at least... |
Codecov Report
@@ Coverage Diff @@
## master #3253 +/- ##
==========================================
+ Coverage 31.2% 32.32% +1.11%
==========================================
Files 229 229
Lines 6428 6562 +134
Branches 1145 1183 +38
==========================================
+ Hits 2006 2121 +115
- Misses 3711 3727 +16
- Partials 711 714 +3
Continue to review full report at Codecov.
|
14b6d54
to
1efd3cc
Compare
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.
Don't know about 1efd3cc, but that would fix it. Otherwise we need to move the focus somewhere inside writing flow at least...
I don't know if we're missing something obvious that this could affect, but it seems like something we can try. We could refine later. If you feel it's good for the 1.6 merge, then 🚢 !
@@ -45,6 +45,16 @@ class WritingFlow extends Component { | |||
this.verticalRect = null; | |||
} | |||
|
|||
componentDidMount() { | |||
document.addEventListener( 'keydown', this.onKeyDown ); |
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.
Do we need these events to be monitored for the whole document? Or just this.container
?
Do we risk bugs with having onKeyDown
now running for any keypress in the document?
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.
Do we risk bugs with having onKeyDown now running for any keypress in the document?
Based on testing master, Yes.
Due to this change, there are massive issues with keyboard navigation. Essentially, pressing up
or down
anywhere will activate this code (even in the toolbar). That is because the react events are being bound to the document
as well, so this is firing even if the component handlers themselves call stopPropagation
.
There is a post explaining how this works:
https://stackoverflow.com/questions/24415631/reactjs-syntheticevent-stoppropagation-only-works-with-react-events
This is forcing component developers to write event.nativeEvent.stopImmediatePropagation
, otherwise their event handler AND this handler will fire. And WritingFlow is pretty much always on the screen, so this handler interferes with almost everything.
Now that we have UI testing, we need to have some basic user navigation tests setup so this kind of thing will be easier to catch in the future.
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.
😱
Just my two cents: (assuming you didn't like the solution proposed by #3194 which was to focus the first editor's outer container, rather than its editable)
My (potentially naive) understanding of all of our keyboard navigation work in the past is that the keys that you press are only supposed to relate to your current focus. Your focus is identifying what should receive keyboard input. If you have shifted focus away from the blocks, then pressing shift + down probably shouldn't do anything, because that is no longer the action that the user is expecting. The screen reader is only going to read what your new focused element is. However, if you're after a different experience from that, it's completely your choice. But beware of making actions respond regardless of where your key position is --- that's where you get conflicts and unexpected behaviour. |
When playing around with #3275 , it highlighted a problem with this approach. It's fine if you want to keep doing a multi-selection and then operate on that selection. But if you want to go back to your single selection (with Shift+Up) it doesn't seem like you can because you've lost the selection and typing does nothing because the editor is no longer focused (you just lose the multi-selection view). I really think we need to find something better than focusing the body. Especially when you consider that you can so easily get into a state with just the keyboard where you can't get back to where you were. |
I agree, we need to move focus somewhere in writing flow. This PR made sure that the editable gets blurred, in addition to that something will have to pick up multi-selection and move focus? |
Ideally multi selection has it's own container wrapping the selected blocks, but that opens its own can of worms. As far as I see, the best thing is still to move it to one of the actions. Or we try what you suggested.
@afercia Any ideas where the focus is best moved when there is a block selection? :) |
Description
Fixes #3191. See also #3194 and #3222.
This PR removes the focus state after a selection is finished. This results in the editable blurring, and therefore fixes deleting the blocks.
The focus implicitly ends up on the body, which is something we may not want.
Additionally this this breaks shift+arrow keys, but it already seems broken in master otherwise too. It seems to rely on a focus in an editable.
How Has This Been Tested?
Checklist: