Icons cannot be child element of links

Created on 19 December 2023, 11 months ago
Updated 29 January 2024, 10 months ago

Problem/Motivation

When adding an icon, you cannot add to an existing link. Nor can you link an icon.

Steps to reproduce

Edit content and try to insert an icon into a link or try and link an icon.

Proposed resolution

Update scheme to allow icons to be child element of links.

Data model changes

Update scheme to allow icons to be child element of links.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States esch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @esch
  • πŸ‡ΊπŸ‡ΈUnited States kevincrafts

    I was able to confirm this issue.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    timurtripp β†’ made their first commit to this issue’s fork.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    Turned out to be more trivial than I expected – simply allowing the linkHref attribute on icons did the trick. The remaining issue is the link balloon clashing with the icon toolbar which may not be as trivial to fix.

  • Assigned to tim.tripp
  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp
  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    Registering an event listener and calling event.stop() should disable the link balloon from showing on click. This is fine as long as the link balloon can still be shown via the link button in the main CKEditor toolbar.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    @esch or @kevinkrafts please review this patch. Hoping this will be sufficient to fix the issue.

  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp
  • πŸ‡ΊπŸ‡ΈUnited States esch

    @ timurtripp I can verify that icons can be linked with the patch.

    However, I have to do it through source view as it is seems the popup menu gets in the way when selecting for linking. Even when I try and put my cursor in the middle of a link, it will break the link into two parts that bookend the icon. Not sure how to get around the popup selection either. If I want the cursor to be after the icon I have to use the arrow keys. If the icon is the last thing in the editor, clicking anywhere in the editor after the icon will select the icon. Thus forcing me to use the arrow keys to move the cursor past it in order to continue entering content. It seems like the popup menu is a bit to aggressive

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    You have to use the arrow keys to place the cursor after a widget that's the last element in the editor, between a widget and a newline, or between two widgets that aren't separated by any text. It seems like that's a CKEditor behavior as in my testing it happens with other widgets as well. Might be a good issue to open with the CKEditor project as I wish it worked a little bit better as well.

    Inserting a new icon in the middle of existing linked text does break the link apart, I'll see if I can fix this. Selecting an existing icon along with some text and linking all of it with a new link works fine in my testing.

  • Status changed to Active 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp
  • πŸ‡ΊπŸ‡ΈUnited States esch

    Agreed that it seems to be a CKEditor5 issue with the widget and using arrows to navigate off them.

    I did test the selection of text + icon for selection of link creation and discovered it is not an issue in chrome but is in Safari. For some reason Safari does not allow the selection of text and a widget for link creation.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    Which version of Drupal / CKEditor are you on? I remember there were some bugs (including a Safari-specific bug I'd encountered) with CKEditor 5 that were fixed, hence why I recommend Drupal 10.1.3 as the minimum version.

  • πŸ‡ΊπŸ‡ΈUnited States esch

    I'm on Drupal 10.2 w/ CKE5.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    Interesting. I can't reproduce this in my version of Safari (16.6), selecting text along with an icon and linking everything seems to work fine.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    If there's no text after the icon then I do have to be more particular about how I select it in Safari than Firefox.

  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp

    @esch Updated patch should enable an icon to be inserted inside the existing link, please verify this is the case.

  • Status changed to Needs review 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp
  • πŸ‡ΊπŸ‡ΈUnited States esch

    @timurtripp I can verify this works in my environment with safari.

    Nice work!

  • Status changed to Fixed 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States tim.tripp
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡ΊπŸ‡ΈUnited States jonathanchris

    Has anyone else ran into an issue when adding icons as a child of a link that has classes applied to it (like bootstrap button classes)? When I do that, even with this patch applied, it splits the link element.

    I also run into this issue when switching back and forth from the source plugin. As well as loading pre-existing content.

  • πŸ‡ΊπŸ‡ΈUnited States jonathanchris

    Please ignore my previous post, I've narrowed my issue down to another plugin ckeditor_details β†’ . My apologies for the false report, thanks for all the efforts on this module!

Production build 0.71.5 2024