1
1
import * as React from 'react' ;
2
2
import { InjectedButtonAttributes } from '../helpers/AccordionStore' ;
3
- import DisplayName from '../helpers/DisplayName' ;
4
3
import {
5
4
focusFirstSiblingOf ,
6
5
focusLastSiblingOf ,
@@ -17,19 +16,17 @@ type Props = DivAttributes & {
17
16
toggleExpanded ( ) : void ;
18
17
} ;
19
18
20
- const defaultProps = {
21
- className : 'accordion__button' ,
22
- } ;
23
-
24
- export class AccordionItemButton extends React . PureComponent < Props > {
25
- static defaultProps : typeof defaultProps = defaultProps ;
26
-
27
- handleKeyPress = ( evt : React . KeyboardEvent < HTMLDivElement > ) : void => {
19
+ const AccordionItemButton = ( {
20
+ toggleExpanded,
21
+ className = 'accordion__button' ,
22
+ ...rest
23
+ } : Props ) => {
24
+ const handleKeyPress = ( evt : React . KeyboardEvent < HTMLDivElement > ) : void => {
28
25
const keyCode = evt . which . toString ( ) ;
29
26
30
27
if ( keyCode === keycodes . ENTER || keyCode === keycodes . SPACE ) {
31
28
evt . preventDefault ( ) ;
32
- this . props . toggleExpanded ( ) ;
29
+ toggleExpanded ( ) ;
33
30
}
34
31
35
32
/* The following block is ignored from test coverage because at time
@@ -68,24 +65,21 @@ export class AccordionItemButton extends React.PureComponent<Props> {
68
65
}
69
66
} ;
70
67
71
- render ( ) : JSX . Element {
72
- const { toggleExpanded, ...rest } = this . props ;
73
-
74
- if ( rest . id ) {
75
- assertValidHtmlId ( rest . id ) ;
76
- }
77
-
78
- return (
79
- < div
80
- { ...rest }
81
- // tslint:disable-next-line react-a11y-event-has-role
82
- onClick = { toggleExpanded }
83
- onKeyDown = { this . handleKeyPress }
84
- data-accordion-component = "AccordionItemButton"
85
- />
86
- ) ;
68
+ if ( rest . id ) {
69
+ assertValidHtmlId ( rest . id ) ;
87
70
}
88
- }
71
+
72
+ return (
73
+ < div
74
+ className = { className }
75
+ { ...rest }
76
+ // tslint:disable-next-line react-a11y-event-has-role
77
+ onClick = { toggleExpanded }
78
+ onKeyDown = { handleKeyPress }
79
+ data-accordion-component = "AccordionItemButton"
80
+ />
81
+ ) ;
82
+ } ;
89
83
90
84
type WrapperProps = Pick <
91
85
DivAttributes ,
@@ -110,6 +104,4 @@ const AccordionItemButtonWrapper: React.SFC<WrapperProps> = (
110
104
</ ItemConsumer >
111
105
) ;
112
106
113
- AccordionItemButtonWrapper . displayName = DisplayName . AccordionItemButton ;
114
-
115
107
export default AccordionItemButtonWrapper ;
0 commit comments