Skip to content

Commit bf4577e

Browse files
committed
Use native hidden attribute instead of d-none
1 parent abfbf50 commit bf4577e

File tree

6 files changed

+22
-21
lines changed

6 files changed

+22
-21
lines changed

app/components/primer/open_project/border_box/collapsible_header.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<%= count %>
77
<% end %>
88
<%= render(Primer::Beta::Octicon.new(icon: "chevron-up", data: { target: "collapsible-header.arrowUp" })) %>
9-
<%= render(Primer::Beta::Octicon.new(icon: "chevron-down", display: :none, data: { target: "collapsible-header.arrowDown" })) %>
9+
<%= render(Primer::Beta::Octicon.new(icon: "chevron-down", hidden: true, data: { target: "collapsible-header.arrowDown" })) %>
1010
<% end %>
1111
<%= flex.with_row do %>
1212
<% if description? %>

app/components/primer/open_project/collapsible_helper.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ export abstract class CollapsibleHelperElement extends HTMLElement {
2323
}
2424

2525
hideAll() {
26-
this.arrowDown?.classList.remove('d-none')
27-
this.arrowUp?.classList.add('d-none')
26+
// For whatever reason, setting `hidden` directly does not work on the SVGs
27+
this.arrowDown.removeAttribute('hidden')
28+
this.arrowUp.setAttribute('hidden', '')
2829

2930
for (const el of this.collapsibleElements) {
30-
el.classList.add('d-none')
31+
el.hidden = true
3132
}
3233

3334
this.classList.add(`${this.baseClass}--collapsed`)
3435
}
3536

3637
expandAll() {
37-
this.arrowDown?.classList.add('d-none')
38-
this.arrowUp?.classList.remove('d-none')
38+
this.arrowUp.removeAttribute('hidden')
39+
this.arrowDown.setAttribute('hidden', '')
3940

4041
for (const el of this.collapsibleElements) {
41-
el.classList.remove('d-none')
42+
el.hidden = false
4243
}
4344

4445
this.classList.remove(`${this.baseClass}--collapsed`)

app/components/primer/open_project/collapsible_section.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<% end %>
1313
<%= header.with_column do %>
1414
<%= render(Primer::Beta::Octicon.new(icon: "chevron-up", data: { target: "collapsible-section.arrowUp" })) %>
15-
<%= render(Primer::Beta::Octicon.new(icon: "chevron-down", display: :none, data: { target: "collapsible-section.arrowDown" })) %>
15+
<%= render(Primer::Beta::Octicon.new(icon: "chevron-down", hidden: true, data: { target: "collapsible-section.arrowDown" })) %>
1616
<% end %>
1717
<%= header.with_column(flex: 1, text_align: :right) do %>
1818
<%= additional_information %>

test/components/primer/open_project/border_box/collapsible_header_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ def test_renders_default
99
render_preview(:default)
1010

1111
assert_selector(".CollapsibleHeader", text: "Backlog")
12-
assert_selector("svg.octicon.octicon-chevron-up")
13-
assert_selector("svg.octicon.octicon-chevron-down.d-none")
12+
assert_selector("svg.octicon.octicon-chevron-up", visible: true)
13+
assert_selector("svg.octicon.octicon-chevron-down", visible: false)
1414
end
1515

1616
def test_does_not_render_without_box
@@ -44,7 +44,7 @@ def test_renders_with_description
4444

4545
assert_selector(".CollapsibleHeader .color-fg-subtle",
4646
text: "This backlog is unique to this one-time meeting. You can drag items in and out to add or remove them from the meeting agenda.")
47-
assert_no_selector(".CollapsibleHeader .color-fg-subtle.d-none")
47+
assert_selector(".CollapsibleHeader .color-fg-subtle", visible: true)
4848
end
4949

5050
def test_renders_with_count

test/system/open_project/border_box/collapsible_header_test.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def test_renders_component
1212
def test_renders_collapsed
1313
visit_preview(:collapsed, module_prefix: "border_box")
1414

15-
assert_selector(".octicon.octicon-chevron-up.d-none", visible: false)
16-
assert_no_selector(".octicon.octicon-chevron-down.d-none")
15+
assert_selector(".octicon.octicon-chevron-up", visible: false)
16+
assert_selector(".octicon.octicon-chevron-down", visible: true)
1717
assert_no_text("This backlog is unique to this one-time meeting. You can drag items in and out to add or remove them from the meeting agenda.")
1818
end
1919

@@ -22,21 +22,21 @@ def test_click_behaviour
2222

2323
# First, make sure it is not collapsed
2424
assert_no_selector(".CollapsibleHeader--collapsed")
25-
assert_selector(".octicon.octicon-chevron-down.d-none", visible: false)
26-
assert_no_selector(".octicon.octicon-chevron-up.d-none")
25+
assert_selector(".octicon.octicon-chevron-down", visible: false)
26+
assert_selector(".octicon.octicon-chevron-up", visible: true)
2727

2828
# Collapse it
2929
find('.CollapsibleHeader').click
3030

3131
assert_selector(".CollapsibleHeader--collapsed")
32-
assert_selector(".octicon.octicon-chevron-up.d-none", visible: false)
33-
assert_no_selector(".octicon.octicon-chevron-down.d-none")
32+
assert_selector(".octicon.octicon-chevron-up", visible: false)
33+
assert_selector(".octicon.octicon-chevron-down", visible: true)
3434

3535
# Expand it again
3636
find('.CollapsibleHeader').click
3737

3838
assert_no_selector(".CollapsibleHeader--collapsed")
39-
assert_selector(".octicon.octicon-chevron-down.d-none", visible: false)
40-
assert_no_selector(".octicon.octicon-chevron-up.d-none")
39+
assert_selector(".octicon.octicon-chevron-down", visible: false)
40+
assert_selector(".octicon.octicon-chevron-up", visible: true)
4141
end
4242
end

test/system/open_project/collapsible_section_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def test_renders_component
1212
def test_renders_collapsed
1313
visit_preview(:collapsed)
1414

15-
assert_selector(".octicon.octicon-chevron-up.d-none", visible: false)
16-
assert_no_selector(".octicon.octicon-chevron-down.d-none")
15+
assert_selector(".octicon.octicon-chevron-up", visible: false)
16+
assert_selector(".octicon.octicon-chevron-down", visible: true)
1717
assert_no_text("How did you hear about us?")
1818
end
1919

0 commit comments

Comments
 (0)