Skip to content

Commit a99c59a

Browse files
committed
Avoid that clicks on links or button in a collapsible section trigger the collapse mechanism
1 parent 083a739 commit a99c59a

5 files changed

Lines changed: 41 additions & 1 deletion

File tree

.changeset/orange-insects-rest.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openproject/primer-view-components': patch
3+
---
4+
5+
Links in collapsible areas do not trigger collapse any more

app/components/primer/open_project/collapsible.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export abstract class CollapsibleElement extends HTMLElement {
1616
}
1717
}
1818

19-
toggle() {
19+
toggle(event?: MouseEvent) {
20+
if (event && (event.target as Element).closest('a, button')) return
2021
this.collapsed = !this.collapsed
2122
}
2223

previews/primer/open_project/collapsible_section_preview.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ def collapsed
5252
locals: { }
5353
)
5454
end
55+
56+
# @label With link in title
57+
# @hidden
58+
def with_link_in_title
59+
render_with_template(
60+
template: "primer/open_project/collapsible_section_preview/with_link_in_title",
61+
locals: { }
62+
)
63+
end
5564
end
5665
end
5766
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<%= render(Primer::OpenProject::CollapsibleSection.new) do |section| %>
2+
<% section.with_title { render(Primer::Beta::Link.new(href: "#")) { "Feedback" } } %>
3+
<% section.with_collapsible_content do %>
4+
<%= render(Primer::Alpha::Banner.new(mb: 3)) { "Please take one minute time to answer this question" } %>
5+
<% end %>
6+
<% end %>

test/system/open_project/collapsible_section_test.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,23 @@ def test_click_behaviour
6464
assert_equal "true", trigger[:'aria-expanded']
6565
assert_selector("##{controlled_id}", visible: true)
6666
end
67+
68+
def test_link_in_title_does_not_collapse
69+
visit_preview(:with_link_in_title)
70+
71+
assert_no_selector(".CollapsibleSection--collapsed")
72+
73+
# Clicking the trigger area (not the link) should still collapse
74+
trigger = find(".CollapsibleSection--triggerArea")
75+
trigger.click
76+
assert_selector(".CollapsibleSection--collapsed")
77+
78+
# Expand again
79+
trigger.click
80+
assert_no_selector(".CollapsibleSection--collapsed")
81+
82+
# Clicking the link should NOT collapse the section
83+
find(".CollapsibleSection--triggerArea a").click
84+
assert_no_selector(".CollapsibleSection--collapsed")
85+
end
6786
end

0 commit comments

Comments
 (0)