Skip to content

Commit

Permalink
fix(accordion): no longer write collapsible to dom in accordion
Browse files Browse the repository at this point in the history
if the accordion was in multipe select then the collapsoble prop is reduncant and was being written
to the dom. This has been stopped by checking the case first.

fix #214
  • Loading branch information
stuarthendren committed Aug 23, 2021
1 parent cb3188b commit f7e0769
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
16 changes: 13 additions & 3 deletions src/components/Accordion/Accordion.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,23 @@ export default {
argTypes: {
type: {
defaultValue: 'single',
control: {
type: 'select',
},
options: ['single', 'multiple'],
description: 'Defines the policy for how many items can be open',
},
collapsible: {
defaultValue: true,
control: {
type: 'boolean',
},
description: 'In single mode only, declares that they can all be closed.',
},
},
} as Meta

export const Default: Story<React.ComponentProps<typeof Accordion>> = ({
...args
}) => {
export const Default: Story = ({ ...args }) => {
return (
<Accordion {...args}>
<AccordionItem value="item-1">
Expand Down
24 changes: 14 additions & 10 deletions src/components/Accordion/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ type AccordionProps = Partial<Polymorphic.OwnProps<typeof Root>> &
CSSProps

export const Accordion = forwardRef<HTMLDivElement, AccordionProps>(
({ collapsible = true, type = 'single', ...props }, forwardedRef) => (
<StyledRoot
type={type}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore This type is allowed when type single.
collapsible={collapsible}
ref={forwardedRef}
{...props}
/>
)
({ collapsible = true, type = 'single', ...props }, forwardedRef) => {
let additionalProps = {}
if (type == 'single' && collapsible) {
additionalProps = { collapsible: true }
}
return (
<StyledRoot
type={type}
{...additionalProps}
ref={forwardedRef}
{...props}
/>
)
}
) as Polymorphic.ForwardRefComponent<
Polymorphic.IntrinsicElement<typeof Root>,
AccordionProps
Expand Down

0 comments on commit f7e0769

Please sign in to comment.