Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(design-system): DS::FilledIcon decorative-vs-meaningful API (#1842)

Guillem Arias Fauste51b03362622f
diff --git a/app/components/DS/filled_icon.html.erb b/app/components/DS/filled_icon.html.erb
index 49adba9e17..9721a26b61 100644
--- a/app/components/DS/filled_icon.html.erb
+++ b/app/components/DS/filled_icon.html.erb
@@ -1,5 +1,8 @@
<%= tag.div style: transparent? ? container_styles : nil,
- class: container_classes do %>
+ class: container_classes,
+ role: (!aria_hidden && description.present?) ? "img" : nil,
+ "aria-label": aria_hidden ? nil : description.presence,
+ "aria-hidden": aria_hidden ? "true" : nil do %>
<% if icon %>
<%= helpers.icon(icon, size: icon_size, color: "current") %>
<% elsif text %>
diff --git a/app/components/DS/filled_icon.rb b/app/components/DS/filled_icon.rb
index 73113a0bce..19ed2e5fa4 100644
--- a/app/components/DS/filled_icon.rb
+++ b/app/components/DS/filled_icon.rb
@@ -1,5 +1,5 @@
class DS::FilledIcon < DesignSystemComponent
- attr_reader :icon, :text, :hex_color, :size, :rounded, :variant
+ attr_reader :icon, :text, :hex_color, :size, :rounded, :variant, :description, :aria_hidden
VARIANTS = %i[default text surface container inverse].freeze
@@ -24,13 +24,26 @@ class DS::FilledIcon < DesignSystemComponent
}
}.freeze
- def initialize(variant: :default, icon: nil, text: nil, hex_color: nil, size: "md", rounded: false)
+ # `description:` makes the icon meaningful — emits `role="img"` +
+ # `aria-label=description` so AT users hear it. Without `description:`,
+ # the wrapper defaults to `aria-hidden="true"` (decorative) on the
+ # assumption that adjacent DOM carries the accessible name. Pass
+ # `aria_hidden: false` if you want the visual exposed but the name
+ # already lives in surrounding text (rare).
+ #
+ # NOTE on the `:text` variant: only `text.first` is rendered (e.g.
+ # "Apple" → "A"). The single letter is decorative — relying on AT
+ # users to infer "Apple" from "A" is broken. Use `description:` to
+ # surface the full label, or ensure the adjacent text node carries it.
+ def initialize(variant: :default, icon: nil, text: nil, hex_color: nil, size: "md", rounded: false, description: nil, aria_hidden: nil)
@variant = variant.to_sym
@icon = icon
@text = text
@hex_color = hex_color
@size = size.to_sym
@rounded = rounded
+ @description = description.presence
+ @aria_hidden = aria_hidden.nil? ? @description.blank? : aria_hidden
end
def container_classes