Skip to content

Commit 376c9ae

Browse files
authored
feat(AccordionHeader): add disabled prop (#6940)
1 parent 4d239e6 commit 376c9ae

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/AccordionHeader.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export interface AccordionHeaderProps
1515
* @default 'accordion-header'
1616
*/
1717
bsPrefix?: string | undefined;
18+
19+
/**
20+
* Disables the button in the header.
21+
*/
22+
disabled?: boolean | undefined;
1823
}
1924

2025
const AccordionHeader: DynamicRefForwardingComponent<
@@ -29,6 +34,7 @@ const AccordionHeader: DynamicRefForwardingComponent<
2934
bsPrefix,
3035
className,
3136
children,
37+
disabled,
3238
onClick,
3339
...props
3440
},
@@ -38,7 +44,11 @@ const AccordionHeader: DynamicRefForwardingComponent<
3844

3945
return (
4046
<Component ref={ref} {...props} className={clsx(className, bsPrefix)}>
41-
<AccordionButton onClick={onClick} aria-controls={ariaControls}>
47+
<AccordionButton
48+
onClick={onClick}
49+
aria-controls={ariaControls}
50+
disabled={disabled}
51+
>
4252
{children}
4353
</AccordionButton>
4454
</Component>

test/AccordionHeaderSpec.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { describe, expect, it } from 'vitest';
1+
import { describe, expect, it, vi } from 'vitest';
22
import { render, screen } from '@testing-library/react';
3+
import userEvent from '@testing-library/user-event';
34
import { AccordionHeader } from '../src';
45

56
describe('<AccordionHeader>', () => {
@@ -10,4 +11,14 @@ describe('<AccordionHeader>', () => {
1011
'test',
1112
);
1213
});
14+
15+
it('should disable the header button when disabled prop is true', async () => {
16+
const user = userEvent.setup();
17+
const onClickFn = vi.fn();
18+
render(<AccordionHeader disabled onClick={onClickFn} />);
19+
20+
await user.click(screen.getByRole('button'));
21+
22+
expect(onClickFn).not.toHaveBeenCalled();
23+
});
1324
});

0 commit comments

Comments
 (0)