Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/Collapse.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
defaultActiveKey,
onChange,
items,
classNames: customizeClassNames,
styles,
} = props;

const collapseClassName = classNames(prefixCls, className);
Expand Down Expand Up @@ -73,6 +75,8 @@ const Collapse = React.forwardRef<HTMLDivElement, CollapseProps>((props, ref) =>
destroyInactivePanel,
onItemClick,
activeKey,
classNames: customizeClassNames,
styles,
});

// ======================== Render ========================
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/useItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import React from 'react';
import type { CollapsePanelProps, CollapseProps, ItemType } from '../interface';
import CollapsePanel from '../Panel';

type Props = Pick<CollapsePanelProps, 'prefixCls' | 'onItemClick' | 'openMotion' | 'expandIcon'> &
type Props = Pick<
CollapsePanelProps,
'prefixCls' | 'onItemClick' | 'openMotion' | 'expandIcon' | 'classNames' | 'styles'
> &
Pick<CollapseProps, 'accordion' | 'collapsible' | 'destroyInactivePanel'> & {
activeKey: React.Key[];
};
Expand All @@ -18,6 +21,8 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
activeKey,
openMotion,
expandIcon,
classNames: collapseClassNames,
styles,
} = props;

return items.map((item, index) => {
Expand Down Expand Up @@ -53,6 +58,8 @@ const convertItemsToNodes = (items: ItemType[], props: Props) => {
return (
<CollapsePanel
{...restProps}
classNames={collapseClassNames}
styles={styles}
prefixCls={prefixCls}
key={key}
panelKey={key}
Expand Down Expand Up @@ -90,6 +97,8 @@ const getNewChild = (
activeKey,
openMotion,
expandIcon,
classNames: collapseClassNames,
styles,
} = props;

const key = child.key || String(index);
Expand Down Expand Up @@ -122,6 +131,8 @@ const getNewChild = (
panelKey: key,
header,
headerClass,
classNames: collapseClassNames,
styles,
isActive,
prefixCls,
destroyInactivePanel: childDestroyInactivePanel ?? destroyInactivePanel,
Expand Down
2 changes: 2 additions & 0 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface CollapseProps {
* @since 3.6.0
*/
items?: ItemType[];
classNames?: Partial<Record<SemanticName, string>>;
styles?: Partial<Record<SemanticName, React.CSSProperties>>;
}

export type SemanticName = 'header' | 'title' | 'body' | 'icon';
Expand Down
4 changes: 2 additions & 2 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -871,12 +871,12 @@ describe('collapse', () => {
const { container } = render(
<Collapse
activeKey={['1']}
styles={customStyles}
classNames={customClassnames}
items={[
{
key: '1',
label: 'title',
styles: customStyles,
classNames: customClassnames,
},
]}
/>,
Expand Down
Loading