Skip to content

Commit

Permalink
feat(minor-button): add position: absolute property to icon when comp…
Browse files Browse the repository at this point in the history
…onent is icon only

adds position: absolute CSS property to `Icon` when component is icon only.
This prevents the rendered `Icon` from moving position on hover due to a reduction
in padding added during `ButtonMinor`s composition, which causes the `Icon` and
Portal used to to provide a tooltip message to stack on top of one another

fix #5946
  • Loading branch information
tomdavies73 committed Apr 20, 2023
1 parent 3a42263 commit b2c906f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cypress/components/button-minor/button-minor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ context("Test for Button Minor component", () => {
}
);

it("when icon only, icon's position is absolute", () => {
CypressMountWithProviders(<ButtonMinor iconType="bin" />);
icon().should("have.css", "position", "absolute");
});

it.each([
[BUTTON_SIZES[0], 32],
[BUTTON_SIZES[1], 40],
Expand Down
12 changes: 12 additions & 0 deletions src/components/button-minor/button-minor.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ButtonTypes,
SizeOptions,
} from "../button/button.component";
import StyledIcon from "../icon/icon.style";
import ButtonMinor from "./button-minor.component";
import { assertStyleMatch } from "../../__spec_helper__/test-utils";

Expand Down Expand Up @@ -88,6 +89,17 @@ describe("Button Minor", () => {
}
);

it("when icon only, icon's position is absolute", () => {
const wrapper = mount(<ButtonMinor iconType="bin" />);
assertStyleMatch(
{
position: "absolute",
},
wrapper,
{ modifier: `${StyledIcon}` }
);
});

it("when destructive prop is passed, renders with destructive styling", () => {
const wrapper = mount(<ButtonMinor destructive>foo</ButtonMinor>);
assertStyleMatch(
Expand Down
8 changes: 8 additions & 0 deletions src/components/button-minor/button-minor.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ function makeColors(color: string) {
}

const StyledButtonMinor = styled(Button)`
${({ children }) =>
!children &&
css`
${StyledIcon} {
position: absolute;
}
`}
${({ buttonType, destructive, disabled }) =>
!destructive &&
!disabled &&
Expand Down

0 comments on commit b2c906f

Please sign in to comment.