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

Fix/issue 5693 firefox focus trap #11601

Merged
1 change: 1 addition & 0 deletions gutenberg-mobile
Submodule gutenberg-mobile added at 776bb2
26 changes: 26 additions & 0 deletions packages/editor/src/components/url-input/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,32 @@ class URLInput extends Component {
// If the suggestions are not shown or loading, we shouldn't handle the arrow keys
// We shouldn't preventDefault to allow block arrow keys navigation
if ( ! showSuggestions || ! posts.length || loading ) {
// This switch statement corrects a bug in Windows Firefox
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anymore context for this bug? What causes it? Is there a link explaining what's happening here or what the bug is?

It would be helpful for future developers to get a bit more info here 😄

The info you wrote up in the original issue (
#5693 (comment)) was handy, so even including that or parts of it (and then linking to the comment for more context) would be great!

switch ( event.keyCode ) {
case UP: {
// If the caret is not in position 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is pretty much describing the if condition below, which is pretty easy to read. But the point here is the caret should be moved to the beginning if it's not there when UP is pressed; it might be better to just explain that here or above the CASE UP: line. 🤷‍♂️

if ( 0 !== event.target.selectionStart ) {
event.stopPropagation();
tofumatt marked this conversation as resolved.
Show resolved Hide resolved
event.preventDefault();

// Set the input caret to position 0
event.target.setSelectionRange( 0, 0 );
}
break;
}
case DOWN: {
// If the caret is not in the last position
if ( this.props.value.length !== event.target.selectionStart ) {
event.stopPropagation();
event.preventDefault();

// Set the inpit caret to the last position
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: should be "input"

event.target.setSelectionRange( this.props.value.length, this.props.value.length );
}
break;
}
}

return;
}

Expand Down