See #2994699-71: Create a CKEditor plugin to select and embed a media item from the Media Library
When using the icon to open Media Library, there's a visual bug in that Image is selected by default (+1) but Audio is also highlighted, causing a visual regression:
@phenaproxima explained that this is because there's code somewhere for accessibility reasons to automatically select the first item in a list. That's good, except that because Image isn't the first thing in the list, it's selecting both.
A workaround was introduced for this in #2994699: Create a CKEditor plugin to select and embed a media item from the Media Library, see :
\Drupal\media_library\Plugin\CKEditorPlugin\DrupalMediaLibrary::getConfig
if (in_array('image', $media_type_ids, TRUE)) {
// Due to a bug where the active item styling and the focus styling
// create the visual appearance of two active items, we'll move
// the 'image' media type to first position, so that the focused item and
// the active item are the same.
// This workaround can be removed once this issue is fixed:
// @see https://www.drupal.org/project/drupal/issues/3073799
array_unshift($media_type_ids, 'image');
$media_type_ids = array_unique($media_type_ids);
}
So this behaviour can only be seen if the workaround is removed.

Comments
Comment #2
phenaproximaComment #4
andrewmacpherson commentedUpdating title. Clarifying that this bug is about the highlight used to indicate a selected tab. The term "focus" gets misused, or is kind-of overloaded.
Comment #6
phenaproximaComment #7
bbu23Hello, I am not able to reproduce the behavior from the screenshot. Could you please share more details of what you are doing to get this result? Thx
Comment #11
lendudeUpdated the IS with notes to the existing workaround that prevents you from reproducing this behaviour currently.
Comment #13
jaykumar95This issue is not reproduced in Claro 9.4.1 theme.
landing from issue https://www.drupal.org/project/drupal/issues/3303889#comment-14655475 to here.
I have found that in patch #91
from https://www.drupal.org/project/drupal/issues/2994699#comment-13214946
the above code prepends the image at first position but as it is an associative array the first pair becomes 0 => "image" instead of "image" => "image"
so to fix it we can use the below code
as I said earlier this issue is not coming in Claro theme we can remove this code block.
Comment #16
bbu23Actually this bug is quite interesting. I have the following scenario on CLARO theme:
On two environments, let's call them:
- LOCAL
- REMOTE
The environments have the same codebase. One of them has the bug, the other one doesn't if we use the non-zero key:
e.g.
What I noticed in REMOTE environment is that the
media_library_allowed_typesarray parameter that is sent to MediaLibraryState gets its keys reordered alphabetically. In MediaLibraryState in construct, even though the parameters are set in the correct order just before, they arrive sorted by keys alphabetically. In the LOCAL environment, the order is kept.If
array_unshift($media_type_ids, 'image');is used in both environments, then the order is not altered anymore because the key 0 will be in the top of the array no matter what.On the remote environment, I changed the image key to be
and then
which showed that the parameters are sorted by keys and placed the Image tab first for the first case, and second for the second case.
This concludes that it is not related to the Claro theme, but I don't know if it's a server issue, or anything else. But since the LOCAL parameters are not sorted at all when they arrive in the MediaLibraryState construct for the exact same code, it could be something else outside of Drupal.
If this is not controllable from Drupal, maybe it would be better to send the parameters to MediaLibraryState with numeric keys instead of alpha keys. This will definitely not require the "image" fix that we currently have. (unless they are required later in the code). E.g.