Skip to content

Commit

Permalink
fix(Button): add robust ReactElements comparison
Browse files Browse the repository at this point in the history
react-hot-loader issue #1267
  • Loading branch information
zhzz committed Apr 1, 2019
1 parent 28bb53a commit 0afca5e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/retail-ui/components/Button/Button.tsx
Expand Up @@ -27,6 +27,10 @@ function listenTabPresses() {
}
}

export const isButton = (child: React.ReactChild): child is React.ReactElement<ButtonProps> => {
return React.isValidElement<ButtonProps>(child) ? child.type.hasOwnProperty('__BUTTON__') : false;
};

export type ButtonSize = 'small' | 'medium' | 'large';

export type ButtonType = 'button' | 'submit' | 'reset';
Expand Down Expand Up @@ -127,6 +131,8 @@ export interface ButtonState {
}

class Button extends React.Component<ButtonProps, ButtonState> {
public static __BUTTON__ = true;

public static TOP_LEFT = Corners.TOP_LEFT;
public static TOP_RIGHT = Corners.TOP_RIGHT;
public static BOTTOM_RIGHT = Corners.BOTTOM_RIGHT;
Expand Down
2 changes: 1 addition & 1 deletion packages/retail-ui/components/Button/index.ts
@@ -1 +1 @@
export { default, ButtonProps, ButtonState, ButtonSize, ButtonType, ButtonUse } from './Button';
export { default, ButtonProps, ButtonState, ButtonSize, ButtonType, ButtonUse, isButton } from './Button';
4 changes: 2 additions & 2 deletions packages/retail-ui/components/Group/Group.tsx
Expand Up @@ -8,7 +8,7 @@ import Corners from '../Button/Corners';
import '../ensureOldIEClassName';
import styles from './Group.less';
import { Nullable } from '../../typings/utility-types';
import Button from '../Button';
import { isButton } from '../Button';

export interface GroupProps {
width?: React.CSSProperties['width'];
Expand Down Expand Up @@ -83,7 +83,7 @@ class Group extends React.Component<GroupProps> {
corners,
};

if (child.type !== Button) {
if (!isButton(child)) {
delete cloneProps.corners;
}

Expand Down

0 comments on commit 0afca5e

Please sign in to comment.