Skip to content
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: Consider tabbable edge if no adjacent tabbable #6542

Merged
merged 1 commit into from
May 8, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented May 2, 2018

This pull request seeks to resolve an error which occurs when making a forward shift selection in the last paragraph of a post, or a backward shift selection in the title.

Uncaught TypeError: Cannot read property 'closest' of undefined

Implementation notes:

closestTabbable may be undefined if there are no more tabbable fields in the desired direction. Since the intent of isTabbableEdge is to discern between there being other tabbables in the same block, it is reasonable to expect this should return true if there are no more tabbables. Where used, this may lead to expandSelection, but this already accounts for the case where there is no adjacent block.

Testing instructions:

Verify backward shift-selection from title results in no errors.
Verify forward shift-selection from last paragraph of content results in no errors.

@aduth aduth added [Type] Bug An existing feature does not function as intended [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... labels May 2, 2018
@jorgefilipecosta
Copy link
Member

jorgefilipecosta commented May 3, 2018

Hi @aduth these changes fix the errors, but I noticed a behavior change when comparing against the master.
On the last paragraph on master when we press shit+down, we select we get an error, but the remaining text of the paragraph gets selected, in this branch no selection happens.
may-03-2018 18-30-24
When pressing arrow+up, we multi-select to the previous paragraph in both branches so in this case, no changes happen.

@aduth
Copy link
Member Author

aduth commented May 4, 2018

Heh, I think this is one of those odd circumstances where the presence of the error was actually providing a desirable behavior.

As implemented, this is expected: When pressing Shift+Down, we prevent the browser default behavior, and only expand the selection if an adjacent block exists:

event.preventDefault();
this.expandSelection( selectedBlockUID, isReverse );

expandSelection( currentStartUid, isReverse ) {
const { previousBlockUid, nextBlockUid } = this.props;
const expandedBlockUid = isReverse ? previousBlockUid : nextBlockUid;
if ( expandedBlockUid ) {
this.props.onMultiSelect( currentStartUid, expandedBlockUid );
}
}

Because no next block exists, it's expected that (a) the browser default is prevented and (b) nothing else happens.

We could revise this so that the browser default is only prevented if the selection can be expanded. That said, it's a bit inconsistent to set expectations for users that Shift+Down can trigger the "select to end of block" behavior for the last block, but no other blocks (where multi-select takes effect instead). What do you think?

In the meantime, since this is "Working as Intended" so far as the current implementation is concerned, I'm inclined to merge as is.

@aduth
Copy link
Member Author

aduth commented May 4, 2018

Also noting that #6467 introduces a new "Writing Flow" end-to-end test suite, which would be a good place to assert whatever behavior we decide upon as being intended.

@aduth aduth merged commit 94e13e3 into master May 8, 2018
@aduth aduth deleted the fix/tabbable-edge-end-of-content branch May 8, 2018 14:19
@mtias mtias added this to the 2.9 milestone May 17, 2018
@mtias
Copy link
Member

mtias commented May 17, 2018

Nice to see the e2e writing flow test setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants