From ae608c501003ea7e34308bc90963b9399bf17dbd Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Fri, 28 Aug 2026 23:58:39 +0900 Subject: [PATCH 1/2] Fix Accordion crash on ArrowUp with a single panel onKeyDownSummary computed the target index from this.props.children.length, which is undefined when children is a single element rather than an array. This produced NaN, and componentDidUpdate then called .focus() on this.summaryButtons[NaN] (undefined), throwing a TypeError. Use React.Children.count, which handles both single and array children. --- components/accordion/index.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/components/accordion/index.jsx b/components/accordion/index.jsx index 2c239ee71..eba55dc8d 100644 --- a/components/accordion/index.jsx +++ b/components/accordion/index.jsx @@ -73,9 +73,11 @@ class Accordion extends Component { ); } + const childCount = React.Children.count(this.props.children); + if (e.key === 'ArrowDown') { e.preventDefault(); - if (buttonIndex < this.props.children.length - 1) { + if (buttonIndex < childCount - 1) { this.setState({ currButtonIndex: buttonIndex + 1, }); @@ -89,7 +91,7 @@ class Accordion extends Component { currButtonIndex: buttonIndex - 1, }); } else { - this.setState({ currButtonIndex: this.props.children.length - 1 }); + this.setState({ currButtonIndex: childCount - 1 }); } } } From c1861d0527ee538769d9ec8854a7829818ca6187 Mon Sep 17 00:00:00 2001 From: Application-drop-up Date: Fri, 28 Aug 2026 23:58:50 +0900 Subject: [PATCH 2/2] Add regression test for Accordion ArrowUp crash with single panel Covers the fix in the previous commit: pressing ArrowUp on the only panel no longer throws. --- .../__tests__/accordion.browser-test.jsx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/components/accordion/__tests__/accordion.browser-test.jsx b/components/accordion/__tests__/accordion.browser-test.jsx index 3a50ef12a..bac575977 100644 --- a/components/accordion/__tests__/accordion.browser-test.jsx +++ b/components/accordion/__tests__/accordion.browser-test.jsx @@ -269,6 +269,23 @@ describe('Accordion', function describeFunction() { lastAccordionButton.getDOMNode() === document.activeElement ).to.equal(true); }); + + it('does not throw on arrow up with only one panel', () => { + wrapper = mount(, { + attachTo: mountNode, + }); + const accordionButtons = wrapper.find( + 'button.slds-accordion__summary-action' + ); + + expect(() => + accordionButtons.at(0).simulate('keyDown', { + key: 'ArrowUp', + keyCode: 38, + which: 38, + }) + ).to.not.throw(); + }); }); describe('Open panel', () => {