@@ -3,43 +3,55 @@ import React from 'react';
3
3
import { css } from '@emotion/core' ;
4
4
import vars from '../../../../materials/custom-properties' ;
5
5
6
- const AccessibleButton = React . forwardRef ( ( props , ref ) => (
7
- < button
8
- id = { props . id }
9
- ref = { ref }
10
- type = { props . type }
11
- aria-label = { props . label }
12
- onClick = { props . onClick }
13
- css = { css `
14
- border : none;
15
- background : none;
16
- display : inline-block;
17
- outline : 0 ;
18
- padding : 0 ;
19
- margin : 0 ;
20
- white-space : nowrap;
21
- cursor : pointer;
22
- color : inherit;
23
- font : inherit;
24
- font-size : ${ vars . fontSizeDefault } ;
25
- font-family : inherit;
6
+ const AccessibleButton = React . forwardRef ( ( props , ref ) => {
7
+ const { onClick } = props ;
26
8
27
- & : disabled {
28
- pointer-events : none;
29
- }
30
- ` }
31
- // Allow to override the styles by passing a `className` prop.
32
- // Custom styles can also be passed using the `css` prop from emotion.
33
- // https://emotion.sh/docs/css-prop#style-precedence
34
- className = { props . className }
35
- disabled = { props . isDisabled }
36
- aria-disabled = { props . isDisabled }
37
- { ...( props . isToggleButton ? { 'aria-pressed' : props . isToggled } : { } ) }
38
- { ...props . buttonAttributes }
39
- >
40
- { props . children }
41
- </ button >
42
- ) ) ;
9
+ const handleClick = React . useCallback (
10
+ event => {
11
+ if ( ! props . isDisabled ) return onClick ( event ) ;
12
+ // eslint-disable-next-line no-useless-return, consistent-return
13
+ return ;
14
+ } ,
15
+ [ onClick , props . isDisabled ]
16
+ ) ;
17
+ return (
18
+ < button
19
+ id = { props . id }
20
+ ref = { ref }
21
+ type = { props . type }
22
+ aria-label = { props . label }
23
+ onClick = { handleClick }
24
+ css = { css `
25
+ border : none;
26
+ background : none;
27
+ display : inline-block;
28
+ outline : 0 ;
29
+ padding : 0 ;
30
+ margin : 0 ;
31
+ white-space : nowrap;
32
+ cursor : pointer;
33
+ color : inherit;
34
+ font : inherit;
35
+ font-size : ${ vars . fontSizeDefault } ;
36
+ font-family : inherit;
37
+
38
+ & : disabled {
39
+ cursor : not-allowed;
40
+ }
41
+ ` }
42
+ // Allow to override the styles by passing a `className` prop.
43
+ // Custom styles can also be passed using the `css` prop from emotion.
44
+ // https://emotion.sh/docs/css-prop#style-precedence
45
+ className = { props . className }
46
+ disabled = { props . isDisabled }
47
+ aria-disabled = { props . isDisabled }
48
+ { ...( props . isToggleButton ? { 'aria-pressed' : props . isToggled } : { } ) }
49
+ { ...props . buttonAttributes }
50
+ >
51
+ { props . children }
52
+ </ button >
53
+ ) ;
54
+ } ) ;
43
55
AccessibleButton . displayName = 'AccessibleButton' ;
44
56
AccessibleButton . propTypes = {
45
57
id : PropTypes . string ,
0 commit comments