Skip to content

Commit

Permalink
refactor(utils): add noOp (empty func) for onTouchStart hack
Browse files Browse the repository at this point in the history
  • Loading branch information
arturbien committed Apr 4, 2020
1 parent b447b88 commit 2662c95
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/components/Button/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createHatchedBackground,
focusOutline
} from '../common';
import { noOp } from '../common/utils';
import { blockSizes } from '../common/system';

const commonButtonStyles = css`
Expand Down Expand Up @@ -132,8 +133,6 @@ const Button = React.forwardRef(function Button(props, ref) {
onClick={disabled ? undefined : onClick}
disabled={disabled}
isDisabled={disabled}
// onTouchStart below to enable button :active style on iOS
onTouchStart={() => ''}
ref={ref}
{...otherProps}
>
Expand All @@ -150,6 +149,8 @@ Button.defaultProps = {
size: 'md',
square: false,
active: false,
// onTouchStart below to enable button :active style on iOS
onTouchStart: noOp,
primary: false,
variant: 'default'
};
Expand All @@ -162,6 +163,7 @@ Button.propTypes = {
size: propTypes.oneOf(['sm', 'md', 'lg']),
square: propTypes.bool,
active: propTypes.bool,
onTouchStart: propTypes.func,
primary: propTypes.bool,
variant: propTypes.oneOf(['default', 'menu', 'flat']),
// eslint-disable-next-line react/require-default-props
Expand Down
13 changes: 8 additions & 5 deletions src/components/TableHeadCell/TableHeadCell.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import propTypes from 'prop-types';

import styled, { css } from 'styled-components';
import { createBorderStyles, createDisabledTextStyles } from '../common';
import { noOp } from '../common/utils';

const StyledHeadCell = styled.th`
position: relative;
Expand Down Expand Up @@ -62,7 +63,6 @@ const TableHeadCell = React.forwardRef(function TableHeadCell(props, ref) {
isDisabled={disabled}
aria-disabled={disabled}
onClick={disabled ? undefined : onClick}
onTouchStart={() => ''}
{...otherProps}
>
<div>{children}</div>
Expand All @@ -71,15 +71,18 @@ const TableHeadCell = React.forwardRef(function TableHeadCell(props, ref) {
});

TableHeadCell.defaultProps = {
onClick: () => {},
children: null,
disabled: false
disabled: false,
onClick: null,
// onTouchStart below to enable :active style on iOS
onTouchStart: noOp
};

TableHeadCell.propTypes = {
onClick: propTypes.func,
children: propTypes.node,
disabled: propTypes.bool
disabled: propTypes.bool,
onClick: propTypes.func,
onTouchStart: propTypes.func
};

export default TableHeadCell;
2 changes: 2 additions & 0 deletions src/components/common/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const noOp = () => {};

export function clamp(value, min, max) {
if (min !== null && value > max) {
return max;
Expand Down

0 comments on commit 2662c95

Please sign in to comment.