File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,11 @@ export interface AccordionHeaderProps
15
15
* @default 'accordion-header'
16
16
*/
17
17
bsPrefix ?: string | undefined ;
18
+
19
+ /**
20
+ * Disables the button in the header.
21
+ */
22
+ disabled ?: boolean | undefined ;
18
23
}
19
24
20
25
const AccordionHeader : DynamicRefForwardingComponent <
@@ -29,6 +34,7 @@ const AccordionHeader: DynamicRefForwardingComponent<
29
34
bsPrefix,
30
35
className,
31
36
children,
37
+ disabled,
32
38
onClick,
33
39
...props
34
40
} ,
@@ -38,7 +44,11 @@ const AccordionHeader: DynamicRefForwardingComponent<
38
44
39
45
return (
40
46
< 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
+ >
42
52
{ children }
43
53
</ AccordionButton >
44
54
</ Component >
Original file line number Diff line number Diff line change 1
- import { describe , expect , it } from 'vitest' ;
1
+ import { describe , expect , it , vi } from 'vitest' ;
2
2
import { render , screen } from '@testing-library/react' ;
3
+ import userEvent from '@testing-library/user-event' ;
3
4
import { AccordionHeader } from '../src' ;
4
5
5
6
describe ( '<AccordionHeader>' , ( ) => {
@@ -10,4 +11,14 @@ describe('<AccordionHeader>', () => {
10
11
'test' ,
11
12
) ;
12
13
} ) ;
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
+ } ) ;
13
24
} ) ;
You can’t perform that action at this time.
0 commit comments