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 link control link preview when it displays long URLs. #60890

Merged
merged 3 commits into from Apr 19, 2024

Conversation

afercia
Copy link
Contributor

@afercia afercia commented Apr 19, 2024

Fixes #60860

What?

The link control 'link preview' layout breaks when it displays long URLs. When this happens, the buttons in the link control are pushed to the right and aren't visible due to the hidden overflow. As such, the important UI controls aren't operable.

Why?

The layout breaks making some controls impossible to use.

How?

The Truncate is expected to truncate long text lines in the link preview. It does so by using the CSS property -webkit-line-clamp. However:

  • The -webkit-line-clamp property works when some text breaks in two or more lines and then it limites the displayed lines to the specified value.
  • As such, a line needs to break in more lines first for the -webkit-line-clamp property to have any effect.
  • Long URLs are treated as 'unbreakable' text by browsers.
  • The addition of the word-break: break-all CSS property makes sure that any text including long URLs break into more lines so that -webkit-line-clamp works as expected.

Testing Instructions

Testing Instructions for Keyboard

Screenshots or screencast

Before:

image

After:

Screenshot 2024-04-19 at 10 14 48

@afercia afercia added [Type] Bug An existing feature does not function as intended [Package] Components /packages/components [Package] Block editor /packages/block-editor [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) labels Apr 19, 2024
@afercia afercia requested a review from ajitbohra as a code owner April 19, 2024 08:46
Copy link

github-actions bot commented Apr 19, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: afercia <afercia@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Thank you, @afercia!

@afercia
Copy link
Contributor Author

afercia commented Apr 19, 2024

Thank you @Mamaduka 👋🏽

@afercia afercia merged commit 8ff4af6 into trunk Apr 19, 2024
61 checks passed
@afercia afercia deleted the fix/link-control-preview-unbreakable-urls branch April 19, 2024 11:39
@github-actions github-actions bot added this to the Gutenberg 18.2 milestone Apr 19, 2024
@jasmussen
Copy link
Contributor

This PR had an unintended side-effect of causing poor word-breaking in the inspector (#61277):

poor text breaking

There's probably a larger question going on here, that would be good to answer. Basically: should the truncation truncate the text only, or also affect the wrapping of text? If the former, we should probably use word-break: break-word; rather than break-all.

Would it be possible to use break-word here instead of break-all? Is there a different way to fix the URL-issue? CC: @Mamaduka @ntsekouras

@jasmussen
Copy link
Contributor

Looks like there's also some left-over CSS that addresses the issue even without adding word-break to the Text component:

Screenshot 2024-05-02 at 12 38 37

@Mamaduka
Copy link
Member

Mamaduka commented May 2, 2024

@afercia is working on an alternative fix in #61137.

@jasmussen
Copy link
Contributor

Fantastic, thanks!

@afercia
Copy link
Contributor Author

afercia commented May 3, 2024

Looks like there's also some left-over CSS that addresses the issue even without adding word-break to the Text component:

For context: Yes, in some cases, some components do add a custom word-break: break-all declaration to the Truncate component because in some cases it's necessary to make long URLs 'breakable'. As far as I can tell, most of these cases are about long URLs of filenames. The alternative fix in #61137 should handle this a littl ebetter and make the 'ad-hoc' word-break: break-all no longer necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) [Package] Block editor /packages/block-editor [Package] Components /packages/components [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LinkControl: LInk preview buttons are off-view when the link text is a very long url
3 participants