Skip to content

Commit 3258eb3

Browse files
authored
Merge pull request #265 from opf/fix/console-erro
Safeguard JS targets for CollapsibleHeaders
2 parents fcd41f6 + aa134f6 commit 3258eb3

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

.changeset/lazy-needles-float.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+
Safeguard CollapsibleHeader class toggling

app/components/primer/open_project/border_box/collapsible_header.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
module Primer
44
module OpenProject
55
module BorderBox
6-
# Add a general description of component here
7-
# Add additional usage considerations or best practices that may aid the user to use the component correctly.
8-
# @accessibility Add any accessibility considerations
6+
# A component to be used inside Primer::Beta::BorderBox.
7+
# It will toggle the visibility of the complete Box body
98
class CollapsibleHeader < Primer::Component
109
status :open_project
1110

app/components/primer/open_project/border_box/collapsible_header.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {attr, controller, target} from '@github/catalyst'
44
class CollapsibleHeaderElement extends HTMLElement {
55
@target arrowDown: HTMLElement
66
@target arrowUp: HTMLElement
7-
@target description: HTMLElement
7+
@target description: HTMLElement | undefined
88

99
@attr collapsed: string
1010
private _collapsed: boolean
@@ -33,23 +33,19 @@ class CollapsibleHeaderElement extends HTMLElement {
3333
}
3434

3535
private hideAll() {
36-
this.arrowDown.classList.remove('d-none')
37-
this.arrowUp.classList.add('d-none')
36+
this.arrowDown?.classList.remove('d-none')
37+
this.arrowUp?.classList.add('d-none')
3838

39-
if (this.description !== undefined) {
40-
this.description.classList.add('d-none')
41-
}
39+
this.description?.classList.add('d-none')
4240

4341
this.classList.add('CollapsibleHeader--collapsed')
4442
}
4543

4644
private expandAll() {
47-
this.arrowDown.classList.add('d-none')
48-
this.arrowUp.classList.remove('d-none')
45+
this.arrowDown?.classList.add('d-none')
46+
this.arrowUp?.classList.remove('d-none')
4947

50-
if (this.description !== undefined) {
51-
this.description.classList.remove('d-none')
52-
}
48+
this.description?.classList.remove('d-none')
5349

5450
this.classList.remove('CollapsibleHeader--collapsed')
5551
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,31 @@ def test_does_not_render_without_title_and_box
2323

2424
def test_does_not_render_with_empty_title
2525
err = assert_raises ArgumentError do
26-
render_inline(render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "", box: "Some component")))
26+
render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "", box: "Some component"))
2727
end
2828

2929
assert_equal "Title must be present", err.message
3030
end
3131

3232
def test_does_not_render_without_valid_box
3333
err = assert_raises ArgumentError do
34-
render_inline(render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "Test title", box: "Some component")))
34+
render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "Test title", box: "Some component"))
3535
end
3636

3737
assert_equal "This component must be called inside the header of a `Primer::Beta::BorderBox`", err.message
3838
end
3939

4040
def test_does_not_render_with_empty_description
4141
err = assert_raises ArgumentError do
42-
render_inline(render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "Test title", box: "Some component", description: "")))
42+
render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "Test title", box: "Some component", description: ""))
4343
end
4444

4545
assert_equal "Description cannot be a blank string", err.message
4646
end
4747

4848
def test_does_not_render_with_empty_count
4949
err = assert_raises ArgumentError do
50-
render_inline(render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "Test title", box: "Some component", count: "")))
50+
render_inline(Primer::OpenProject::BorderBox::CollapsibleHeader.new(title: "Test title", box: "Some component", count: ""))
5151
end
5252

5353
assert_equal "Count cannot be a blank string", err.message

0 commit comments

Comments
 (0)