Skip to content

Commit

Permalink
fix(button): disabled button triggering onClick
Browse files Browse the repository at this point in the history
  • Loading branch information
bramvanhoutte committed May 4, 2020
1 parent 45c4223 commit 4c9cf4b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
8 changes: 2 additions & 6 deletions src/components/Button/Button.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.base {
.button {
border-radius: var(--border-radius-small);
line-height: 32px;
font-size: 14px;
Expand Down Expand Up @@ -36,16 +36,12 @@
background-color: var(--color-secondary);
}

.base:disabled {
.button:disabled {
color: var(--color-disabled-font);
background-color: var(--color-disabled);
cursor: default;
}

.label {
text-align: center;
}

.labelWithPrefixIcon {
margin-left: 8px;
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ const Button: React.FC<Props> = ({
name,
}: Props) => {
const buttonClassNames = classNames(
styles.base,
styles.button,
{
[styles.typePrimary]: (!isDisabled || !isLoading) && type === 'primary',
[styles.typeSecondary]: (!isDisabled || !isLoading) && type === 'secondary',
[styles.typePrimary]: type === 'primary',
[styles.typeSecondary]: type === 'secondary',
},
className,
);

const labelClassNames = classNames(styles.label, {
const labelClassNames = classNames({
[styles.labelWithPrefixIcon]: Boolean(prefixIcon) || isLoading,
[styles.labelWithSuffixIcon]: Boolean(suffixIcon),
});
Expand All @@ -47,7 +47,7 @@ const Button: React.FC<Props> = ({
disabled={isDisabled || isLoading}
className={buttonClassNames}
type="button"
onClick={onClick}
onClick={isLoading || suffixIcon ? onClick : undefined}
data-testid={`button-${name}`}
>
{isLoading ? <Spinner className={styles.spinner} /> : prefixIcon}
Expand Down

0 comments on commit 4c9cf4b

Please sign in to comment.