Skip to content

Commit 2662c95

Browse files
committed
refactor(utils): add noOp (empty func) for onTouchStart hack
1 parent b447b88 commit 2662c95

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/components/Button/Button.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
createHatchedBackground,
1414
focusOutline
1515
} from '../common';
16+
import { noOp } from '../common/utils';
1617
import { blockSizes } from '../common/system';
1718

1819
const commonButtonStyles = css`
@@ -132,8 +133,6 @@ const Button = React.forwardRef(function Button(props, ref) {
132133
onClick={disabled ? undefined : onClick}
133134
disabled={disabled}
134135
isDisabled={disabled}
135-
// onTouchStart below to enable button :active style on iOS
136-
onTouchStart={() => ''}
137136
ref={ref}
138137
{...otherProps}
139138
>
@@ -150,6 +149,8 @@ Button.defaultProps = {
150149
size: 'md',
151150
square: false,
152151
active: false,
152+
// onTouchStart below to enable button :active style on iOS
153+
onTouchStart: noOp,
153154
primary: false,
154155
variant: 'default'
155156
};
@@ -162,6 +163,7 @@ Button.propTypes = {
162163
size: propTypes.oneOf(['sm', 'md', 'lg']),
163164
square: propTypes.bool,
164165
active: propTypes.bool,
166+
onTouchStart: propTypes.func,
165167
primary: propTypes.bool,
166168
variant: propTypes.oneOf(['default', 'menu', 'flat']),
167169
// eslint-disable-next-line react/require-default-props

src/components/TableHeadCell/TableHeadCell.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import propTypes from 'prop-types';
33

44
import styled, { css } from 'styled-components';
55
import { createBorderStyles, createDisabledTextStyles } from '../common';
6+
import { noOp } from '../common/utils';
67

78
const StyledHeadCell = styled.th`
89
position: relative;
@@ -62,7 +63,6 @@ const TableHeadCell = React.forwardRef(function TableHeadCell(props, ref) {
6263
isDisabled={disabled}
6364
aria-disabled={disabled}
6465
onClick={disabled ? undefined : onClick}
65-
onTouchStart={() => ''}
6666
{...otherProps}
6767
>
6868
<div>{children}</div>
@@ -71,15 +71,18 @@ const TableHeadCell = React.forwardRef(function TableHeadCell(props, ref) {
7171
});
7272

7373
TableHeadCell.defaultProps = {
74-
onClick: () => {},
7574
children: null,
76-
disabled: false
75+
disabled: false,
76+
onClick: null,
77+
// onTouchStart below to enable :active style on iOS
78+
onTouchStart: noOp
7779
};
7880

7981
TableHeadCell.propTypes = {
80-
onClick: propTypes.func,
8182
children: propTypes.node,
82-
disabled: propTypes.bool
83+
disabled: propTypes.bool,
84+
onClick: propTypes.func,
85+
onTouchStart: propTypes.func
8386
};
8487

8588
export default TableHeadCell;

src/components/common/utils/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export const noOp = () => {};
2+
13
export function clamp(value, min, max) {
24
if (min !== null && value > max) {
35
return max;

0 commit comments

Comments
 (0)