Skip to content

Commit

Permalink
fix(Button): display variant only when set (#5458)
Browse files Browse the repository at this point in the history
This bugfix aligns the `<button>` variant class implementation with
Alert/Badge/Navbar -- only outputing a `prefix-variant` formatted class
when a variant is specified and avoiding the situation of outputting
`.btn-null` or `.btn-` when the variant is null or an empty string
respectively

Split from #5456
  • Loading branch information
davidjb committed Oct 1, 2020
1 parent 526ea4e commit f963ab3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const Button: Button = React.forwardRef(
className,
prefix,
active && 'active',
`${prefix}-${variant}`,
variant && `${prefix}-${variant}`,
block && `${prefix}-block`,
size && `${prefix}-${size}`,
);
Expand Down
18 changes: 18 additions & 0 deletions test/ButtonSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ describe('<Button>', () => {
mount(<Button>Title</Button>).assertSingle(`.btn-primary`);
});

it('Should remove default variant', () => {
mount(<Button variant={null}>Title</Button>)
.find(`.btn-primary`)
.should.have.length(0);
});

it('Should not output null variant', () => {
mount(<Button variant="">Title</Button>)
.find(`.btn-null`)
.should.have.length(0);
});

it('Should not output empty variant', () => {
mount(<Button variant="">Title</Button>)
.find(`.btn-`)
.should.have.length(0);
});

it('Should be active', () => {
mount(<Button active>Title</Button>).assertSingle(`.active`);
});
Expand Down

0 comments on commit f963ab3

Please sign in to comment.