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

SegmentedControl: Don't update selected state on links #1571

Merged
merged 2 commits into from
Nov 3, 2022
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/honest-worms-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/view-components": patch
---

SegmentedControl: Don't update selected state on links
2 changes: 1 addition & 1 deletion app/components/primer/alpha/segmented_control/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(label:, selected: false, icon: nil, hide_labels: false, **system_
@selected = selected

@system_arguments = system_arguments
@system_arguments[:"data-action"] = "click:segmented-control#select"
@system_arguments[:"data-action"] = "click:segmented-control#select" if system_arguments[:href].nil?
@system_arguments[:"aria-current"] = selected
@system_arguments[:scheme] = :invisible
end
Expand Down
10 changes: 10 additions & 0 deletions test/components/primer/alpha/segmented_control_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def test_renders_full_width
assert_selector("segmented-control ul.SegmentedControl.SegmentedControl--fullWidth")
end

def test_doesnt_use_control_click_with_href
render_inline(Primer::Alpha::SegmentedControl.new) do |c|
c.with_item(icon: :zap, label: "Item 1", selected: true) { "Item 1" }
c.with_item(tag: :a, href: "#", icon: :zap, label: "Item 2") { "Item 2" }
end

assert_selector("button[data-action=\"click:segmented-control#select\"]", count: 1)
assert_selector("a[data-action=\"click:segmented-control#select\"]", count: 0)
end

def test_doesnt_render_with_too_many_items
error = assert_raises(ArgumentError) do
render_inline(Primer::Alpha::SegmentedControl.new) do |c|
Expand Down