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 regressions and improve the insert link search field and suggestions list #10838

Merged
merged 5 commits into from
Nov 8, 2018

Conversation

afercia
Copy link
Contributor

@afercia afercia commented Oct 20, 2018

Fixes #10820

Additionally fixes a few CSS regressions and improves the interaction with the insert link search field and suggestions list.

First commit:

  • regression: makes the list of suggestions scrollable again when using a keyboard and the list is longer than the max-height (it worked in 2.9.0)
  • regression: fixes the input padding after 38378c8 which broke the usage of the variable in the padding calculation
  • regression: fixes the spinner position for the same reason

Worth noting:

  • I couldn't reproduce the original issue mentioned in Fix issue with link dialog. #8646 because there's now a 1 pixel padding that makes the focus style visible so I just reverted the variable to 8px
  • re: the padding on the right: seems to me there's nothing to display in that space so I'm not sure why the padding was meant to be 44px; changed to 8px

Second commit:

  • makes the TAB key populate the search field with the highlighted link URL
  • this allows keyboard users to select the link (not submit yet) and tab to the Link Settings button; matches the current interaction in the Classic Editor
  • adds a speak message to announce the link has been selected, matches the current interaction in the Classic Editor
  • when clicking on a suggested link, moves focus to the search field: matches the current interaction in the Classic Editor and clarifies a further action (submit) is needed
  • changes the Link added. message to Link inserted to match the Classic Editor message

Third commit:

screen shot 2018-10-20 at 00 32 52

Basically, this happens because the "Link Settings" button is now placed outside of the first popover:
screen shot 2018-10-20 at 17 12 26

Thus, the calculation of the suggestions popover is based on the search field form without the settings button. I can think of two ways to fix this:

  • either move back the "Link Settings" button within the form (not sure if this is possible / desirable)
  • or use a custom getAnchorRect function to get the grand parent node

I've opted for the latter, even if a better solution would probably be making the popover component handle these nesting cases. I'd appreciate some eyes form @aduth and @talldan. If there's the need for adjustments / refinements / improvements glad if you can take this PR and make it better.

  • adds 2 pixels to the suggestions list width to match the search field popover width (it has now an additional 1 pixel padding)
  • removes width: 100%; from the search field because it made the following "Apply" button smaller than it's supposed to be (the correct width is 36 pixels)
  • removes a stray list-style: none; applied on a div

Re: the popover position when a popover is nested within another popover, I guess this relates also to #8468.

@afercia afercia added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Regression Related to a regression in the latest release labels Oct 20, 2018
@afercia afercia requested review from talldan and aduth October 20, 2018 18:15
* position. As the popover with the list of suggestions is now nested within
* another popover, we need to get the gran parent node.
*/
return anchor.parentNode.parentNode.getBoundingClientRect();
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the logic, but I'd prefer if we find another way as this seems fragile. It used to work properly before without it (even with two popovers) so curious to know why it regressed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree it's fragile, that's why I've mentioned that maybe the popover component should handle these nesting cases internally. It happened to work before just by coincidence 🙂 If you look at the screenshot posted above, the suggestions list is perfectly centered to the first popover highlighted area. The ellipsis button is now outside of the first popover and doesn't contribute to determine its width, so the position calculation of the second popover takes into consideration only the highlighted area. If you move the ellipsis button back inside the first popover, then the position will work correctly (but just by coincidence).

this.props.onChange( post.url, post );
this.setState( {
selectedSuggestion: null,
showSuggestions: false,
} );

// Announce a link has been selected when tabbing away from the input field.
if ( event.keyCode === TAB ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why should we only announce this on "tab" only? I prefer to do it consistently if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because when pressing Enter, the form is submitted and the link gets inserted. There's another speak message for that, see "Link inserted" in submitLink() in LinkContainer.

Copy link
Contributor

Choose a reason for hiding this comment

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

Gotcha, instead of passing the event object here, I'd personally just move this to the switch/case above

@afercia
Copy link
Contributor Author

afercia commented Oct 21, 2018

Thanks @youknowriad

  • tried to use the TAB / ENTER cases and dry up a bit to avoid duplicated code
  • when a suggested item gets clicked with the mouse, focus must be returned on the search field: using a new handleOnClick() for this

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Nice, Thanks for the improvements.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Actually, this broken the url input for the button block.

@afercia
Copy link
Contributor Author

afercia commented Oct 21, 2018

Ah, right. I see the custom getAnchorRect() doesn't work on the Button block because it gets the wrong parent and needs the default behavior instead.
Not sure I see other differences from master (or even previous versions), am I missing something? Aside: the interaction on the Button block would need some work.

@afercia
Copy link
Contributor Author

afercia commented Oct 22, 2018

I've reverted the custom getAnchorRect() as that's not a proper solution. However, the position thing is still a problem, I guess it would be better addressed separately. Also, I'd tend to think the URL input / popover implementation needs some refinement, looking at it holistically. FOr example, I'm not sure I understand why the Button block URL input doesn't have a "Link Settings" button: as a used, I can I set that link to open in a new tab?

screen shot 2018-10-22 at 08 31 05

@desrosj desrosj added this to the WordPress 5.0 milestone Oct 25, 2018
@gziolo gziolo modified the milestones: WordPress 5.0, 4.4 Nov 5, 2018
@youknowriad youknowriad modified the milestones: 4.4, 4.3 Nov 7, 2018
@youknowriad
Copy link
Contributor

Can you rebase the branch so we can get it in.

@afercia afercia force-pushed the fix/link-search-field-and-suggestions-fixes branch from 444e68f to 6bd3ae2 Compare November 8, 2018 08:31
@afercia
Copy link
Contributor Author

afercia commented Nov 8, 2018

Rebased. Thank you.

@talldan
Copy link
Contributor

talldan commented Nov 8, 2018

I had a test - looks good. A simple solution to the positioning of the autcomplete suggestions might be to make it a child of the editor-url-input div:
screen shot 2018-11-08 at 4 46 33 pm

Will need to make it a bit narrower, but I think it's still wide enough to cover most post titles.

I think we should tackle that in a separate PR though.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@afercia afercia merged commit e12f2b4 into master Nov 8, 2018
@afercia afercia deleted the fix/link-search-field-and-suggestions-fixes branch November 8, 2018 09:04
@afercia
Copy link
Contributor Author

afercia commented Nov 12, 2018

I think we should tackle that in a separate PR though.

@talldan has a PR been created? I've just noticed one more issue: as the ellipsis button is now placed outside, pressing Escape when it's focused or when its expanded panel is focused, doesn't close the link popover.

@talldan
Copy link
Contributor

talldan commented Nov 13, 2018

Hi @afercia - here's a PR tackling that - #11803

I'll also see if I can solve the escape key issue now. (apologies for these regressions)

edit: here's the PR for the escape key issue - #11806

@aduth
Copy link
Member

aduth commented Jan 13, 2020

makes the TAB key populate the search field with the highlighted link URL [...] adds a speak message to announce the link has been selected, matches the current interaction in the Classic Editor

Was it intentional that we only announce that the link has been selected when explicitly pressing the Tab key, and not when selecting the link via Enter ? I could see an argument being made that since it might not be expected that the link is selected when the focus shifts by pressing Tab, the spoken message helps inform the user about that effect. But if it's unexpected such that it needs to be explained, then it makes me wonder whether it should actually happen at all.

In other words, would you consider either of the following as a reasonable change:

  1. Always announce that the link is selected, regardless of whether it occurs by Tab or by Enter
  2. Or, remove the behavior where a link is selected as a result of pressing Tab

Edit: After spending more time with links (related to #19462), I'm now aware there are expected to be different specific behaviors of Tab and Enter insofar as both "select" a link, but only when pressing Enter is the link actually applied. At least, this is how it works today. It's not necessarily something that the URLInput ought to be opinionated about, considering that it doesn't actually handle the application of the link in response to an Enter press, but I can see how the changes here were modeled after that expected outcome. Technically, since both keys would cause a link to become "selected", it could still be reasonable to expect the spoken message to happen in response to either of the two keys. But I could also see how that might cause some confusion for how the Enter key results not only in the selection of the link, but also the application of that link to the selected text (the submission of the form).

@afercia
Copy link
Contributor Author

afercia commented Jan 21, 2020

Generally, the Tab key should be reserved for keyboard navigation so the most important thing is that it doesn't insert a link.

If I recall correctly, the current behavior is meant to reproduce how wplink always worked in WordPress. That's the behavior keyboard and assistive technology users are used to.

In a way, that's not totally unexpected. Some browsers have the same behavior on some native HTML elements. For example on a <select> element on macOS:

  • Firefox: pressing Tab selects the highlighted option
  • Webkit (Chrome, Safari, Opera): pressing Tab doesn't do anything

Worth noting that when pressing Enter, wplink does announce Link inserted. so I'd vote for option 1

Always announce that the link is selected, regardless of whether it occurs by Tab or by Enter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Links suggestions: suggestions list doesn't scroll when using a keyboard
6 participants