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
12 changes: 11 additions & 1 deletion src/AccordionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export interface AccordionHeaderProps
* @default 'accordion-header'
*/
bsPrefix?: string | undefined;

/**
* Disables the button in the header.
*/
disabled?: boolean | undefined;
}

const AccordionHeader: DynamicRefForwardingComponent<
Expand All @@ -29,6 +34,7 @@ const AccordionHeader: DynamicRefForwardingComponent<
bsPrefix,
className,
children,
disabled,
onClick,
...props
},
Expand All @@ -38,7 +44,11 @@ const AccordionHeader: DynamicRefForwardingComponent<

return (
<Component ref={ref} {...props} className={clsx(className, bsPrefix)}>
<AccordionButton onClick={onClick} aria-controls={ariaControls}>
<AccordionButton
onClick={onClick}
aria-controls={ariaControls}
disabled={disabled}
>
{children}
</AccordionButton>
</Component>
Expand Down
13 changes: 12 additions & 1 deletion test/AccordionHeaderSpec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { describe, expect, it } from 'vitest';
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { AccordionHeader } from '../src';

describe('<AccordionHeader>', () => {
Expand All @@ -10,4 +11,14 @@ describe('<AccordionHeader>', () => {
'test',
);
});

it('should disable the header button when disabled prop is true', async () => {
const user = userEvent.setup();
const onClickFn = vi.fn();
render(<AccordionHeader disabled onClick={onClickFn} />);

await user.click(screen.getByRole('button'));

expect(onClickFn).not.toHaveBeenCalled();
});
});