-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Force disable suggestions until URL field is dirty in Link Control #51354
Conversation
Size Change: +14 B (0%) Total Size: 1.39 MB
ℹ️ View Unchanged
|
@@ -126,6 +126,7 @@ const LinkControlSearchInput = forwardRef( | |||
return ( | |||
<div className="block-editor-link-control__search-input-container"> | |||
<URLInput | |||
disableSuggestions={ currentLink?.url === value } |
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.
value
here is the url
(only) not the full value
object.
// The URL search suggestion should not exist. | ||
expect( lastSearchResultItem ).not.toHaveTextContent( searchTerm ); | ||
expect( lastSearchResultItem ).not.toHaveTextContent( 'URL' ); | ||
expect( lastSearchResultItem ).not.toHaveTextContent( | ||
'Press ENTER to add this link' | ||
); |
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.
These assertions were accidentally modified to .not
which allowed the test to pass. However, the test itself no longer applies and makes sense because we actually don't want the URL to show up as a fallback anymore. We test against this elsewhere so it's safe to remove this one now.
// Ensure no initial suggestions are shown. | ||
expect( | ||
screen.queryByRole( 'listbox', { |
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 diff isn't the best. Basically I'm changing the test to actually assert that no suggestions are shown. Previously we replied on focusing the input to trigger showing the results which had absolutely no merit that I can see.
Now this functionality is being removed anyway so it makes sense to fix and simplify the test.
Flaky tests detected in 1b1baef. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5215428476
|
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 looks good and works as expected.
Just noting that link control in the navigation block works differently to the one in the post editor - in that case the suggestions are still shown. Is that expected?
No it's not 🤔 |
I spent a lot more time looking into this. The reason for the difference in behaviour in the navigation link component is that it provides a I think we should merge this and consider if we want to change that behaviour separately. |
Thank you very much for looking into this. I really do appreciate it. That said, I'm slightly nervous that we merged this if there's any unusual behaviour still at play. Maybe it's just me 🤷 We will all need to keep a close eye on this. cc @richtabor who might notice changes in behaviour as he's working in/around this component at the moment as well. |
…ordPress#51354) * Force disable suggestions if internal and current value match * Fix broken and outdated tests * Add test coverage
What?
Changes the control to not show suggestions immediately on focusing the input.
Part of #50885
Why?
Currently on
trunk
as soon as you focus theURL
field search suggestions are shown. This seems to have been intentional but it is now undesirable (@richtabor to confirm).Instead we only want to show suggestions if the
URL
changes been modified (i.e. it is "dirty").How?
Supplies the
disableSuggestions
prop if the currentvalue
object'surl
property matches the current internalurl
property. In this case the field is not dirty and thus we do not want to show suggestions.Testing Instructions
URL
fieldTesting Instructions for Keyboard
Screenshots or screencast
Before
Screen.Capture.on.2023-06-08.at.21-18-33.mp4
After
Screen.Capture.on.2023-06-08.at.21-17-39.mp4