Skip to content

Commit

Permalink
Remove duplicate aria-label in CloseButton (#1805)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcsmith authored Feb 2, 2023
1 parent 12bace8 commit 238328a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/tidy-months-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@primer/view-components': patch
---

Update CloseButton to work with more aria-label types
2 changes: 1 addition & 1 deletion app/components/primer/beta/close_button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def initialize(type: DEFAULT_TYPE, **system_arguments)
"close-button",
system_arguments[:classes]
)
@system_arguments[:"aria-label"] ||= "Close"
@system_arguments[:"aria-label"] = aria("label", system_arguments) || "Close"
end

def call
Expand Down
14 changes: 14 additions & 0 deletions test/components/beta/close_button_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,22 @@ def test_does_not_render_as_block
end

def test_can_override_aria_label
# Test with nested hash style `aria-label`
render_inline(Primer::Beta::CloseButton.new(aria: { label: "Label" }))
assert_selector("button[type='button'][aria-label='Label'].close-button")

# Ensure the default `aria-label` is not in the generated HTML
#
# Note: Must use `refute_includes` instead of `refute_selector`. If there
# are duplicate attributes on a given element, Capybara will ignore the second one.
# So if we use `refute_selector` the test will pass even if there is a duplicate
# `aria-label` in the generated HTML.
refute_includes @rendered_content, 'aria-label="Close"'

# Test with String style `aria-label`
render_inline(Primer::Beta::CloseButton.new("aria-label": "Label"))

assert_selector("button[type='button'][aria-label='Label'].close-button")
refute_includes @rendered_content, 'aria-label="Close"'
end
end

0 comments on commit 238328a

Please sign in to comment.