Problem/Motivation
When a user uploads an icon for a button, especially if it is an SVG without explicit width/height or with big width/height attributes, the lack of a size limit might break the design of the table.
Note that uploading SVGs is something that might become more and more common as CKE5 will force us to only accept SVGs.
Steps to reproduce
- Upload a SVG without widht/height attributes or with a big value. Examples used for testing, obtained from a popular SVG icon library.
<svg xmlns="http://www.w3.org/2000/svg" width="600" height="600" fill="#000000" viewBox="0 0 256 256"></svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="#000000" viewBox="0 0 256 256"></svg>
- The table will suffer as the <img> will be sized by the SVG attributes (or lack of them) and the icon will be completely out of proportion.
Without explicit attributes:

With large atribute values (600px), something not so unusual when getting SVG files.

Proposed resolution
Cap the heigth of the image, using max-height to avoid enlarging of smaller icons while keeping larger icons controlled.
For example, using max-height: 2rem results on this:

The first icon is a big svg capped at 2rem, the other icons are smaller pngs that don't get enlarged.
| Comment | File | Size | Author |
|---|---|---|---|
| Screenshot_20221122_170313.png | 23.64 KB | idiaz.roncero | |
| Screenshot_20221122_170846.png | 12.64 KB | idiaz.roncero | |
| Screenshot_20221122_170431.png | 46.59 KB | idiaz.roncero |
Issue fork embed-3323180
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3323180-cap-icon-height
changes, plain diff MR !9
Comments
Comment #3
idiaz.ronceroSubmitted a pretty basic MR that uses inline CSS to solve this.
Using
heightattributes directly on the<img>tag won't work as they are normally overriden via css for responsive images;I think for such a tiny fix CSS inline is not bad, but if needed this could be solved more "drupally" just by attaching a small library with the CSS tweak.
Comment #4
dave reidSince this is related to SVGs I'm going to merge this into #3310328: When CKEditor5 is installed, only allow SVGs for button icons where I'm just setting a height and width *both* of 32px by default in the listing and the edit form preview.