fix: Accordion crash on ArrowUp with a single panel - #3192
Conversation
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.
Covers the fix in the previous commit: pressing ArrowUp on the only panel no longer throws.
|
Thanks for opening this pull request! 💯 This is a community-driven project, and we can't do it without your participation. Please check out our contributing guidelines and review the Contributor Checklist if you haven't already, to make sure everything is squared away. CircleCI will take about 10 minutes to run through the same items that are on the Contributor checklist with a pass/fail check below. Please fix any issues that cause CircleCI to fail or ask for clarification--we try, but sometimes the errors can be unclear. |
Fixes #
This PR fixes a crash in onKeyDownSummary in
components/accordion/index.jsxthat occurred when the Accordion had only a single panel — pressing ArrowUp produced NaN instead of a valid index.It also adds a regression test in
components/accordion/__tests__/accordion.browser-test.jsxto prevent it from recurring.Additional description
CONTRIBUTOR checklist (do not remove)
Please complete for every pull request
npm run lint:fixhas been run and linting passes.components/component-docs.jsonCI tests pass (npm test).REVIEWER checklist (do not remove)
components/component-docs.jsontests.Required only if there are markup / UX changes
last-slds-markup-reviewinpackage.jsonand push.last-accessibility-review, topackage.jsonand push.npm run local-updatewithin locally cloned site repo to confirm the site will function correctly at the next release.