-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Update Accordion component default behavior to match USWDS #922
feat: Update Accordion component default behavior to match USWDS #922
Conversation
…t for shallow copy of openItems variable in order to implement default behavior of one item expanded at a time, comments for tests to be done
…nt items simultaneously when multiselectable is true
}, | ||
className | ||
) | ||
|
||
const toggleItem = (itemId: AccordionItem['id']): void => { | ||
const newOpenItems = [...openItems] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sooo ... it turns out that const
in TypeScript just means you cannot reassign the variable. You can still invoke methods that change the object.
Here's a playground that shows adding an element to a const
array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking really good! I have a few small suggestions 🎉
…replacing the let I removed with const again and using splice to empty the array for default behavior
@@ -61,20 +62,26 @@ export const Accordion = (props: AccordionProps): React.ReactElement => { | |||
'usa-accordion', | |||
{ | |||
'usa-accordion--bordered': bordered, | |||
'aria-multiselectable': multiselectable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is supposed to be a CSS class! instead, the Accordion <div>
should have the aria-multiselectable
attribute if multiselectable is true (I'm comparing with the source code at https://designsystem.digital.gov/components/accordion/)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thank you for catching that.
…v instead of a className
@SirenaBorracha LGTM. I didn't approve bc right now it looks like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small thing, then I'm good to approve!
…lse to match USWDS syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking care of that! Approved 👍
BREAKING CHANGE: If the multiselectable behavior is desired, the multiselectable prop must now be passed to the Accordion component
BREAKING CHANGE: To continue to use the multiselectable behavior, use the multiselectable prop
Summary
This PR adds an optional
multiselectable
property to the Accordion component. In order to match the default behavior of the USWDS Accordion, the default value of themultiselectable
property isfalse
, so that only one item in the Accordion may be opened at a time. Optionally settingmultiselectable
totrue
allows for multiple items in the accordion to be expanded simultaneously.The github issue identifies this as a "feat" but I'm wondering if it shouldn't be a "fix" ?
Related Issues or PRs
Github issue #207
How To Test
Checkout this branch and run
yarn storybook
To see the intended default behavior
To see the behavior when
multiselectable
istrue
Screenshots (optional)
Accordion with two items expanded
Accordion with all items expanded