-
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
Fix: Bug on URLInput & Intermitent end to end test on the buttons block #19490
Fix: Bug on URLInput & Intermitent end to end test on the buttons block #19490
Conversation
Can you explain why it should have to wait? If we're using a plain URL, it shouldn't need to care that any search results exist for the entered input? (Just want to make sure we're not covering up a legitimate bug where a user might not be able to insert a link for a plain URL if search results haven't yet populated) |
Hi @aduth thank you for sharing your thoughts 👍 We were pressing enter and right after we were checking the markup from the store:
I think the bug happened because after enter is pressed things need to be processed and it may take some time until getEditedPostContent() returns the markup with the link. That said I will need to restart the tests a few times to confirm this PR fixes the issue.
If that's the case, I think this fix should not hide that issue because we are waiting after enter is pressed and not before while search results are being populated |
According to the build failure, the test which was meant to be corrected is still failing, now with:
From the |
162b52c
to
35cbc6e
Compare
Hi @aduth, Steps to reproduce: In this PR pressing enter inserts the link right away even if the request was not finished. |
I haven't looked in too much detail yet, but I wonder if the recent change might have some impact (improvement or conflict) on issues described at #19056 / #18933 (comment) . I know some of these link components use a (I notice we're not |
35cbc6e
to
35e3da5
Compare
@@ -179,6 +183,11 @@ class URLInput extends Component { | |||
} | |||
break; | |||
} | |||
case ENTER: { | |||
event.preventDefault(); |
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.
What is this preventing
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.
Not sure, for the current enter keypress code we were calling "event.preventDefault();" so I followed similar logic. But, it seems the calls to event.preventDefault(); are not needed so I removed them.
@@ -214,9 +223,12 @@ class URLInput extends Component { | |||
break; | |||
} | |||
case ENTER: { |
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.
What about the above case for TAB
? It seems like it has an identical expected behavior, where it's selecting a link (but also with an explicit speak
announcement?)
I wonder if we should just remove the condition on selectedSuggestion
in both places, then handle a null/empty/undefined suggestion
from selectLink
as the current input value.
35e3da5
to
55ed619
Compare
I applied some changes to this PR: |
I don't know that we can force the current value to be passed up as the This object is supposed to represent a post object. We can imitate some of these properties using the input value as a raw URL, but it seems prone to issues if we're communicating it as if it were a post, when it's not necessarily a post. Based on some of my observations in #19462 (especially #19462 (comment)), I think we have some misunderstanding in what it's supposed to mean to "select" a link. If I understand correctly, With that in mind: I don't think we want to try to force the value to be treated as a selected suggestion, because that only perpetuates this idea that I think the true issue is a combination of:
|
<div class=\\"wp-block-button\\"><a class=\\"wp-block-button__link\\">WordPress</a></div> | ||
<div class=\\"wp-block-button\\"><a class=\\"wp-block-button__link\\" href=\\"https://www.wordpress.org/\\" title=\\"https://www.wordpress.org/\\">WordPress</a></div> |
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.
This change highlights another issue: I think we shouldn't want to assign a title
attribute here? Based on what a title
would be used for (advisory information), I would think it less meaningful than the text it's supposedly meant to advise.
It also seems like it could be an accessibility concern, to the extent that I might question whether we want to be surfacing title
at all from LinkControl
.
References:
Relying on the title attribute is currently discouraged as many user agents do not expose the attribute in an accessible manner as required by this specification (e.g., requiring a pointing device such as a mouse to cause a tooltip to appear, which excludes keyboard-only users and touch-only users, such as anyone with a modern phone or tablet).
https://html.spec.whatwg.org/multipage/dom.html#the-title-attribute
Or: https://silktide.com/blog/2013/i-thought-title-text-improved-accessibility-i-was-wrong
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.
title
should only be used to provide legitimate context to the link. It shouldn't repeat the link text. Therefore if the title
isn't handcrafted by the user then it should be omitted.
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.
title
should only be used to provide legitimate context to the link. It shouldn't repeat the link text. Therefore if thetitle
isn't handcrafted by the user then it should be omitted.
@getdave You might also be interested in my comment at #19462 (comment) , where I share a few more resources which would seem to support the claim that the title
attribute should never be used for links.
Do you have any more context for the value we were hoping to get out of it?
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.
- We probably want to remove this
onSelect
handling, and only track the changes. The Enter behavior to select a link should take effect by the form'sonSubmit
.
I've been tracking this bug over at #19458.
I didn't fix it but came to the same conclusions as you. I believe we should approve this from the perspective of how we would craft this form if React were not a thing (ie: in plain old semantic HTML).
In this scenario we'd have a form
with a submit handler that manages the value. For some reason we're not doing that and it's necessitating all kinds of bespoke keyboard handlers and also causing console warnings.
I agree that a rewrite of this logic is required.
@@ -179,6 +183,10 @@ class URLInput extends Component { | |||
} | |||
break; | |||
} | |||
case ENTER: { | |||
// If pressing enter before suggestions are loaded use the current input as the link. | |||
setCurrentInputAsLink(); |
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.
This is exactly what I was thinking of doing in my PR. However, I decided it was probably papering over the cracks and we should rewrite the form submit handler logic instead.
@@ -52,6 +52,7 @@ async function updateActiveNavigationLink( { url, label } ) { | |||
await page.type( 'input[placeholder="Search or type url"]', url ); | |||
// Wait for the autocomplete suggestion item to appear. | |||
await page.waitForXPath( `//span[@class="block-editor-link-control__search-item-title"]/mark[text()="${ url }"]` ); | |||
await page.keyboard.press( 'ArrowDown' ); |
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.
Question: if we're entering a direct URL then should we have to use arrow to select an option before submitting the link back to the consuming component?
I'd say that you should be able to add whatever you type into the box using the ENTER
key without first having to select the URL search suggestion.
In the future this PR will mean that URL search results actually mean something (ie: display data from the remote URL) but at the moment they are really only visual and serve no purpose.
Superseded by #19490 |
Thank you for fixing this issue 👍 |
Description
Buttons had an end to end test that fails from time to time.
This PR adds a waitForSelector call to avoid this failure.
How has this been tested?
I executed the end to end tests for the buttons block multiple times and verified they consistently pass.