11import * as React from 'react' ;
22import { InjectedButtonAttributes } from '../helpers/AccordionStore' ;
3- import DisplayName from '../helpers/DisplayName' ;
43import {
54 focusFirstSiblingOf ,
65 focusLastSiblingOf ,
@@ -17,19 +16,17 @@ type Props = DivAttributes & {
1716 toggleExpanded ( ) : void ;
1817} ;
1918
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 => {
2825 const keyCode = evt . which . toString ( ) ;
2926
3027 if ( keyCode === keycodes . ENTER || keyCode === keycodes . SPACE ) {
3128 evt . preventDefault ( ) ;
32- this . props . toggleExpanded ( ) ;
29+ toggleExpanded ( ) ;
3330 }
3431
3532 /* The following block is ignored from test coverage because at time
@@ -68,24 +65,21 @@ export class AccordionItemButton extends React.PureComponent<Props> {
6865 }
6966 } ;
7067
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 ) ;
8770 }
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+ } ;
8983
9084type WrapperProps = Pick <
9185 DivAttributes ,
@@ -110,6 +104,4 @@ const AccordionItemButtonWrapper: React.SFC<WrapperProps> = (
110104 </ ItemConsumer >
111105) ;
112106
113- AccordionItemButtonWrapper . displayName = DisplayName . AccordionItemButton ;
114-
115107export default AccordionItemButtonWrapper ;
0 commit comments