Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClipboardCopy only needs aria-label when empty #1244

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/good-coats-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Stop requiring aria-label on ClipboardCopy with other content.
8 changes: 6 additions & 2 deletions app/components/primer/clipboard_copy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ClipboardCopy < Primer::Component
# <%= render(Primer::ClipboardCopy.new(value: "Text to copy", "aria-label": "Copy text to the system clipboard")) %>
#
# @example With text instead of icons
# <%= render(Primer::ClipboardCopy.new(value: "Text to copy", "aria-label": "Copy text to the system clipboard")) do %>
# <%= render(Primer::ClipboardCopy.new(value: "Text to copy")) do %>
# Click to copy!
# <% end %>
#
Expand All @@ -34,10 +34,14 @@ def initialize(value: nil, **system_arguments)
@system_arguments[:value] = value if value.present?
end

# :nodoc:
def before_render
validate_aria_label if content.blank?
end

private

def validate!
validate_aria_label
raise ArgumentError, "Must provide either `value` or `for`" if @value.nil? && @system_arguments[:for].nil?
end
end
Expand Down
10 changes: 9 additions & 1 deletion test/components/clipboard_copy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ def test_renders_simple
end
end

def test_requires_aria_label_when_empty
assert_raises(ArgumentError) do
render_inline Primer::ClipboardCopy.new(value: "my-branch-name") do
nil
end
end
end

def test_renders_with_text_contents
render_inline Primer::ClipboardCopy.new(value: "my-branch-name", "aria-label": "Copy branch name to clipboard") do
render_inline Primer::ClipboardCopy.new(value: "my-branch-name") do
"Click to copy!"
end

Expand Down