Feature request: SVG should conform to ClassAttributeModifier
Package: swift-web-standards
Type: Missing conformance / feature request
Severity: Moderate — workaround required for common use case
Description
The SVG struct (in the SVG module) does not conform to ClassAttributeModifier, so the fluent .class() method is unavailable on SVG values.
This is very common in practice — SVG icons embedded in HTML almost always need a CSS class for sizing, colour, or visibility control:
Svg.icon(.eye)
.setAttribute(name: ":class", value: "{ hidden: !show }")
.class("w-4 h-4 text-gray-500") // ❌ error: value of type 'SVG' has no member 'class'
Expected behaviour
SVG should support .class() just like HTML elements do, since SVG is embedded directly in HTML and styled with the same CSS class system.
Workaround
Declare a retroactive conformance in the consuming package:
import SVG
import HTML
extension SVG: @retroactive ClassAttributeModifier {}
Suggested fix
In the SVG module, either:
- Add
ClassAttributeModifier to SVGTag's protocol requirements, or
- Provide a concrete
.class() implementation on SVGTag directly using setAttribute(name: "class", value: ...).
Option 2 avoids importing HTML from the SVG module:
// In SVGTag extension
public func `class`(_ value: String) -> Self {
setAttribute(name: "class", value: value)
}
Feature request:
SVGshould conform toClassAttributeModifierPackage: swift-web-standards
Type: Missing conformance / feature request
Severity: Moderate — workaround required for common use case
Description
The
SVGstruct (in theSVGmodule) does not conform toClassAttributeModifier, so the fluent.class()method is unavailable onSVGvalues.This is very common in practice — SVG icons embedded in HTML almost always need a CSS class for sizing, colour, or visibility control:
Expected behaviour
SVGshould support.class()just like HTML elements do, since SVG is embedded directly in HTML and styled with the same CSS class system.Workaround
Declare a retroactive conformance in the consuming package:
Suggested fix
In the SVG module, either:
ClassAttributeModifiertoSVGTag's protocol requirements, or.class()implementation onSVGTagdirectly usingsetAttribute(name: "class", value: ...).Option 2 avoids importing HTML from the SVG module: