Skip to content

A platform for community discussion. Free, open, simple.

FIX: Stop browsers from clipping icons that draw outside their viewBox (#44786)

Kris0fdc20224927
diff --git a/lib/svg_sprite.rb b/lib/svg_sprite.rb
index 4bbee230033..d8353117a3b 100644
--- a/lib/svg_sprite.rb
+++ b/lib/svg_sprite.rb
@@ -326,6 +326,9 @@ module SvgSprite
icon_id = prepare_symbol(sym, svg_filename)
if icon_id.present?
sym.attributes["id"].value = icon_id
+ # Some glyphs draw outside their viewBox; Firefox and Safari clip a <use> symbol
+ # to its viewBox unless overflow is set on the symbol itself (page CSS can't reach it)
+ sym["overflow"] = "visible"
sym.css("title").each(&:remove)
[icon_id, sym.to_xml]
end
diff --git a/spec/lib/svg_sprite/svg_sprite_spec.rb b/spec/lib/svg_sprite/svg_sprite_spec.rb
index 1bde7cff60c..2cee868c06d 100644
--- a/spec/lib/svg_sprite/svg_sprite_spec.rb
+++ b/spec/lib/svg_sprite/svg_sprite_spec.rb
@@ -17,6 +17,13 @@ RSpec.describe SvgSprite do
expect(bundle).to match(/angles-down/)
end
+ it "lets symbols draw outside their viewBox" do
+ symbols = Nokogiri.XML(SvgSprite.bundle).css("symbol")
+
+ expect(symbols).to be_present
+ expect(symbols.map { |symbol| symbol["overflow"] }.uniq).to eq(["visible"])
+ end
+
it "can generate paths" do
version = SvgSprite.version # Icons won't change for this test