-
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
Fix Link UI when hyperlink has an empty href
value
#35043
Conversation
@javierarce I couldn't seem to find the correct icon for the one you used in the mockup in #17972 (comment). I'll happily swap out if you let me know. |
Size Change: +276 B (0%) Total Size: 1.07 MB
ℹ️ View Unchanged
|
@getdave I used the 'alert' icon from the generic list. |
I've tested this branch, and it works great if you manually set the link to an empty string. It also works fine if you click the link icon or use command k and then press enter, but if you just introduce one or more spaces, the interface still shows the empty state. Could we consider avoiding inserting a link if the user presses enter and either the field length is 0 or just contains spaces? |
I was working on this bit in a separate PR but now wondering if it needs fixing here as well. I'll update here as to my progress. |
@javierarce I think you're saying you can create an empty link by hitting |
@javierarce Looks like that doesn't exist in the https://github.com/WordPress/gutenberg/tree/trunk/packages/icons/src/library See also https://wordpress.github.io/gutenberg/?path=/story/icons-icon--library. Can I just add a new icon to the package? |
@javierarce Done |
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.
🚀
f44b8ca
to
be3f275
Compare
Rebasing to see if that will get the RN tests to go green. |
I see your point 👍 I wonder how useful these empty links are anyway, e.g. consider how #35060 disallows creating them inside Gutenberg. Would it make sense to do the same for the parser and parse |
Is it worth considering that this might be an error state introduced by accident? For example, what if someone went poking around in the "Code view" and tried their hand at editing HTML by hand and broke the link by removing the href. If we simply remove the link at the parser level, the author will potentially not notice that the link has disappeared. If they do notice and re-create it, they will also have lost any other attributes applied to that link so they'll have to redo all the config. If we show an invalid UI state however, the author will know something went wrong and have a chance to correct it. Moreover, any existing attributes will be preserved. That said, I imagine that is an edge case scenario. The HTML spec says links without |
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.
All good points @getdave, let's do it!
For example, what if someone went poking around in the "Code view" and tried their hand at editing HTML by hand and broke the link by removing the href.
Yeah accidentally breaking the href isn't too clear in either scenario – chances are I won't click that link even if the formatting is there. Might be worth exploring separately one day.
be3f275
to
a1e8f94
Compare
Description
In #17972 (comment) we learnt that if any inline link (within paragraph text) has an empty
href
then the Link UI can end up in an unexpected "preview" state. This UI state provides no feedback to the user as to the cause of the error.This PR resolves that by switching to rendering an "error" state in the link preview if the
value
'surl
prop is empty.This does not attempt to resolve the situation where you create an empty link using the Link UI. That's handled in a companion PR.
Fixes #17972 (comment)
Why does this happen?
Back when it was created a
forceIsEditingLink
prop was addd to the<LinkControl>
in order to force it in and out of "editing" mode.This was then utilised in the "inline link" part of the format library to allow various user UI actions (example) to trigger the Link UI.
However, this allows for an edge case - if
forceIsEditingLink
is set tofalse
and thevalue.url
is falsey then:value.url
property.Other options considered
I did consider updating the
<LinkControl>
to reverse the effect offorceIsEditingLink
if:forceIsEditingLink
isfalse
, AND...value.url
is empty.If I had done that then even if
forceIsEditingLink
wasfalse
then the Link UI would not render the preview or the editing mode because of the absence of a validvalue.url
.I decided not to pursue this as the prop is very explicitly forcing a state on the LinkControl and therefore I wanted to avoid "magic" within the component subverting that "instruction".
How has this been tested?
We have a new unit test coverage for this scenario.
You can also manually test:
href
to an empty string.Screenshots
Screen.Capture.on.2021-09-22.at.13-56-56.mp4
Types of changes
Bug fix (non-breaking change which fixes an issue)
Checklist:
*.native.js
files for terms that need renaming or removal).