Closed (fixed)
Project:
External Links
Version:
2.0.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
22 Sep 2020 at 10:41 UTC
Updated:
5 Sep 2024 at 15:43 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
sasanikolic commentedHere is a patch with an initial proposal of a new setting to attach the icon to the link as a pseudo element. However, I'm not happy with the custom Fontawesome 5 styles, how can we handle that in this module?
Comment #3
neslee canil pinto@sasanikolic patch failed to apply, needs reroll
Comment #4
sasanikolic commentedSorry about that. Let's try with this one.
Comment #5
neslee canil pinto@sasanikolic lets wait for the test result
Comment #6
sasanikolic commentedI made some improvements for the new setting to be dependent on the Fontawesome icon setting.
However, this only works if "Web fonts with CSS" setting is selected in the Fontawesome module and with FA5. Would need some help on how to properly deal with that.
Comment #7
miro_dietikerThis line confuses me as both cases seem to end up in the same assignment?
Mind below a different thing "extFaMailtoClasses" is used.
Also, the "mailtoLabel" is completely skipped.
Can we somehow streamline the spaghetti of cases to build these 2*2+ variations?
Comment #9
dotmundo commentedFWIW, we had this problem where icon would line break when using an HTML header (H1, H2, H3, etc...). The patch did not work in our case probably because the TWIG template and JS code was very poorly structure but I came up with a simple fix.
Rather than do this in your template code:
<a href="https://www.drupal.org"><h3>Go to Drupal website</h3></a>... just do this...
<h3><a href="https://www.drupal.org">Go to Drupal website</a></h3>It might not meet some coding standards but it worked for me.
Comment #10
dotmundo commentedFWIW, we had this problem where icon would line break when using an HTML header (H1, H2, H3, etc...). The patch did not work in our case probably because the TWIG template and JS code was very poorly structure and would require a complete redesign. Instead I came up with a simple fix.
Rather than do this in your HTML
<a href="https://www.drupal.org"><h3>Go to Drupal website</h3></a>... just do this...
<h3><a href="https://www.drupal.org">Go to Drupal website</a></h3>This might not meet HTML coding standards but it works
Comment #11
itmaybejj commentedHere's another approach altogether.
If the module is set to append, it looks for the last text node in the link, wraps it in a span, and inserts the image or FA class into the span rather than the parent link. The span's class prevents wrapping.
From:
<a href class="ext">Link Text ⤴️</a>To:
<a href class="ext">Link <span class="extlink-nobreak">Text ⤴️</span></a>In my testing this works fine for the various nestings of
<a><h2>, as well as more complex links with images.If you are testing locally, note that it falls back to default behavior when Twig debugging injects an HTML comment at the end of a link around a media item.
Comment #12
itmaybejj commentedComment #13
pivica commentedQuick update based on original issue description and old comments from @sasanikolic.
Internally we figured out that the main problem we have is with FA CSS default rule
This rule will break icon to the next line as a single word if there is not enough room. In our base custom theme we will just add CSS override for this like
and this simple fix is enough to improve icon line wrapping behaviour - now if there is not enough space the icon will wrap together with last word which looks much better.
Granted you will get a different text underline behavior now with icon inline display (text decoration underline will have a small break), but this is not possible to fix with current CSS and hopefully CSS 4 version will bring in the future new rules for controlling underline behavior better. Until then if you do not like disconnected underline you can switch to border-bottom or pseudo after element CSS approach.
Also i think it will look better with disconnected underline, then without any underline on icon part which we currently have with inline-block rule.
We need to test this a bit more in custom projects, but it seems it is working great for now. Based on this I would recommend we drop very complex JS change approach for fixing this in previous patch and then just close this issue or maybe consider adding some similar rule in extlink CSS.
Comment #14
bkosborneUsing font-awesome icons is an optional feature - we're using SVGs
Comment #15
pivica commented> Using font-awesome icons is an optional feature - we're using SVGs
The original issue and patches from @sasanikolic targeted Font Awesome case and not SVG inline images.
Not sure about the approach in comment 11 didn't checked/tested that one.
Quickly checked locally using of SVG images instead of FA icons. For me there were two problems for mailto icon:
1. Provided SVG image form mailto had buggy default viewBox definition of `viewBox="0 10 70 20"`. Even without looking into browser this aspect ratio of 70 to 10 just sounds very wrong. Changing that to something like `viewBox="0 0 60 60"` is giving much better result.
This SVG definition is acutally coming also from JS extlink.js file:
Beside wrong viewBox definition there is a lot of weird stuff going on in this SVG and this should be optimized much better like probably removing metadata tag and everything inside of it. Same goes for ext SVG image definition - it needs cleanup and check of viewBox definition.
2. Then I just needed to add next CSS rule to make stuff look OK:
Depending what look you want you would probably want to add some spacing between text and svg icon horizontally, but that also depends on your design. Anyway this looks good enough and more importantly wrapping works in the same way as for FA case with display inline.
Based on this I still think this should be fixed just with simple CSS changes and not with adding more JS code and complexity in that layer.
Comment #16
itmaybejj commentedI think the SVG icons need the JS approach in #11.
But if display:inline did work for FontAwesome, the extra JS could be set to only fire when the module config is set to SVG.
Comment #17
pivica commentedI just found out that there is `text-wrap: balance` CSS option which works great in improving text wrapping of element, including any icon it has.
It is still not supported in Safari but it is in TP for desktop version. Check more on https://caniuse.com/css-text-wrap-balance.
Comment #18
smustgrave commentedComment #19
smustgrave commentedCurious instead of a js solution if prepend/append can be done with just css and if after/before gets a wrapper around the link and icon?
Comment #21
vidorado commentedI'm not 100% sure, but a purely CSS solution would require having the FA font available for using it in a
font-familyCSS property and using Unicode characters in thecontentCSS attribute of the::afterand::beforepseudo-elements.Regarding your question about the "wrapper around the link and icon": if I understand correctly, you are asking whether a wrapper is being used or not, correct? I have conducted some tests and found that it is not. The icon is simply placed before the
<a>element.In any case, I've tested the solution in #11 and it works well for me, even though I have tricky CSS in my anchor, with a
spaninside that has adisplay: block. So I've added it to the MR.Comment #25
smustgrave commentedWill include with next release of 2.0.x
Comment #27
arakwarWhile I can understand the logic behind this, I have to point out that it can break existing themes... Having no way of turning that new behavior off is an issue.
Comment #28
runbits commentedEchoing #27's concern here.
The intentions of this change are fine for "normal links" that contain multiple words.
But maybe no thought was put into 'mailto:' links, where there is typically no natural word breaks in the link's text.
For example: firstname.lastname@longdomainnamehere.com
Our sites had CSS that forced email-address links to wrap if necessary. Extlink's new "extlink-nobreak" markup and CSS overrides that now, and in narrow spaces - like sidebars or cards in a grid-layout - we get a broken layout (horizon overflow, scrollbars) or text that gets cutoff (in cases where the parent container has `overflow: hidden`).
The CSS we were using to ensure long email address links did not break horizontal flow.
a[href^="mailto"] { overflow-wrap: break-word; }---
Our temporary workaround is to completely disable Extlink's processing of 'mailto:' links in the module's options.
Comment #29
smustgrave commentedWould recommend a new ticket to address future enhancements of the feature.