Skip to content

Commit 3b277b3

Browse files
committed
fix: keep SVG viewBox so icons scale instead of clipping
SVGR (via @svgr/rollup) runs SVGO's preset-default, which strips the viewBox from icons that carry width/height attributes. Without a viewBox, rendering an icon below its intrinsic 16px (e.g. size-3 in small buttons) crops the drawing to the smaller viewport instead of scaling it. Edge-to-edge glyphs like PEN visibly clip. Override removeViewBox in the rollup build so the viewBox is preserved and icons scale at any size. Note: Storybook uses vite-plugin-svgr, which does not run SVGO by default (only the jsx plugin), so it already preserves the viewBox and needs no change.
1 parent 87bc673 commit 3b277b3

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

.changeset/keep-svg-viewbox.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@aragon/gov-ui-kit": patch
3+
---
4+
5+
Keep the `viewBox` on bundled SVG icons so they scale correctly when rendered below their intrinsic 16px size (e.g. `size-3` in small buttons) instead of being clipped.

rollup.config.mjs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,19 @@ export default [
5252
],
5353
}),
5454
images({ include: ['**/*.png', '**/*.jpg'] }),
55-
svgr(),
55+
svgr({
56+
// Keep the viewBox so icons scale instead of getting clipped when
57+
// rendered at a size other than their intrinsic 16px (e.g. size-3 in
58+
// small buttons). SVGO's preset-default removes it by default.
59+
svgoConfig: {
60+
plugins: [
61+
{
62+
name: 'preset-default',
63+
params: { overrides: { removeViewBox: false } },
64+
},
65+
],
66+
},
67+
}),
5668
terser(),
5769
],
5870
},

0 commit comments

Comments
 (0)