Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(minor-button): add position: absolute property to icon when component is icon only #5971

Merged
merged 2 commits into from
Apr 24, 2023

Conversation

tomdavies73
Copy link
Contributor

@tomdavies73 tomdavies73 commented Apr 14, 2023

fix #5946

Proposed behaviour

This PR will add 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 ButtonMinors composition, which causes the Icon and Portal used to to provide a tooltip message to stack on top of one another

2023-04-14 12 10 25

Current behaviour

Currently, the Icon rendered within the component and Portal used to to provide a tooltip message stack on top of one another, this is due to the rendred Icon having relative positioning, which is needed for other variants of the button and a reduction in padding implemented during the components composition.

2023-04-14 12 09 44

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Screenshots are included in the PR if useful
  • All themes are supported if required
  • Unit tests added or updated if required
  • Cypress automation tests added or updated if required
  • Storybook added or updated if required
  • Translations added or updated (including creating or amending translation keys table in storybook) if required
  • Typescript d.ts file added or updated if required
  • Related docs have been updated if required

QA

  • Tested in CodeSandbox/storybook
  • Add new Cypress test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

The following CodeSandbox is an example of the broken behaviour.
You can see the new behaviour by looking at the version in the comment by codesandbox[bot].

@codesandbox-ci
Copy link

codesandbox-ci bot commented Apr 14, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a9923bf:

Sandbox Source
carbon-quickstart Configuration
carbon-quickstart-typescript Configuration
carbon-quickstart PR

@cypress
Copy link

cypress bot commented Apr 14, 2023

Passing run #15934 ↗︎

0 5140 35 0 Flakiness 0

Details:

Merge branch 'master' into FE-5742
Project: carbon Commit: a9923bf97c
Status: Passed Duration: 05:52 💡
Started: Apr 24, 2023 1:25 PM Ended: Apr 24, 2023 1:31 PM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

Parsium
Parsium previously approved these changes Apr 14, 2023
@tomdavies73 tomdavies73 changed the title fix(minor-button): refactor use of padding on component feat(minor-button): add position: absolute property to icon when a tooltip message is passed Apr 18, 2023
@@ -17,6 +17,16 @@ function makeColors(color: string) {
}

const StyledButtonMinor = styled(Button)`
${({ iconType, iconTooltipMessage, children }) =>
iconType &&
iconTooltipMessage &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need all these conditions.

I see that we need to check for an icon-only button (with the !children check), otherwise the icon overlaps the text when both are present. But iconTooltipMessage makes no difference here (as far as I can tell), and iconType isn't needed simply because without that there's no StyledIcon inside for the styles to affect.

I prefer it checking just this one condition as it makes the code simpler with fewer special cases.

@@ -88,6 +89,19 @@ describe("Button Minor", () => {
}
);

it("when icon only with tooltip message, icon's position is absolute", () => {
const wrapper = mount(
<ButtonMinor iconType="bin" iconTooltipMessage="foo" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make the code change I suggested,the iconTooltipMessage prop won't be needed in this prop (and we can leave it out of the test description).

@@ -94,6 +94,13 @@ context("Test for Button Minor component", () => {
}
);

it("when icon only with tooltip message, icon's position is absolute", () => {
CypressMountWithProviders(
<ButtonMinor iconType="bin" iconTooltipMessage="foo" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make the code change I suggested,the iconTooltipMessage prop won't be needed in this prop (and we can leave it out of the test description).

@tomdavies73 tomdavies73 changed the title feat(minor-button): add position: absolute property to icon when a tooltip message is passed feat(minor-button): add position: absolute property to icon when component is icon only Apr 20, 2023
@tomdavies73 tomdavies73 force-pushed the FE-5742 branch 2 times, most recently from 96f2230 to 2aa4d5a Compare April 20, 2023 10:25
const wrapper = mount(<ButtonMinor iconType="bin">Foo </ButtonMinor>);
assertStyleMatch(
{
position: "undefined",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
position: "undefined",
position: undefined,

I'm surprised your version works, I guess all values get coerced to a string somewhere in assertStyleMatch. But we don't want the CSS position value to be "undefined", we want it to be not there (corresponding to JS undefined, which isn't a string).

…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
@tomdavies73 tomdavies73 marked this pull request as ready for review April 24, 2023 08:47
@tomdavies73 tomdavies73 requested review from a team as code owners April 24, 2023 08:47
@tomdavies73 tomdavies73 merged commit f52992a into master Apr 24, 2023
@tomdavies73 tomdavies73 deleted the FE-5742 branch April 24, 2023 13:42
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 118.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Button Minor with Tooltip - Icon moves up vertically when hovered
5 participants