Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/yoga/src/Accordion/web/Accordion.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import styled, { css } from 'styled-components';
import { string, node, bool } from 'prop-types';
import { string, node, bool, shape } from 'prop-types';
import { ChevronDown } from '@gympass/yoga-icons';
import { Text, Divider } from '../..';
import Content from './Content';
Expand Down Expand Up @@ -206,6 +206,7 @@ const Accordion = ({
expanded,
small,
hasHorizontalPadding,
headerProps,
...props
}) => {
const [open, setOpen] = useState(expanded);
Expand All @@ -220,9 +221,13 @@ const Accordion = ({
disabled={disabled}
onClick={() => {
setOpen(o => !o);
if (typeof headerProps.onClick === 'function') {
headerProps.onClick();
}
Comment on lines +224 to +226
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof headerProps.onClick === 'function') {
headerProps.onClick();
}
headerProps.onClick?.();

}}
small={small}
hasHorizontalPadding={hasHorizontalPadding}
{...headerProps}
>
{hasSummary ? (
summary
Expand Down Expand Up @@ -270,6 +275,9 @@ Accordion.propTypes = {
expanded: bool,
small: bool,
hasHorizontalPadding: bool,
/** if provided displays a button below the item text. It accepts all button
* element props */
headerProps: shape({}),
};

Accordion.defaultProps = {
Expand All @@ -279,6 +287,7 @@ Accordion.defaultProps = {
expanded: false,
small: false,
hasHorizontalPadding: true,
headerProps: {},
};

export default Accordion;