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

Prevent .show-on-focus to change width/height #2391

Merged
merged 3 commits into from
Feb 28, 2023
Merged

Prevent .show-on-focus to change width/height #2391

merged 3 commits into from
Feb 28, 2023

Conversation

simurai
Copy link
Contributor

@simurai simurai commented Feb 27, 2023

What are you trying to accomplish?

This came up in Slack. Currently the .show-on-focus utility sets the width/height to auto when focused. This is fine for most elements but causes the new .Button--iconOnly to loose its fixed width/height.

What approach did you choose and why?

This PR...

  • moves most of the properties into a :not(:focus) selector. This makes sure that the :focus selector doesn't need to set the width/height to auto.
  • uses !important to override longer selectors and other utilties.
  • adds a story so we can document .show-on-focus on https://primer.style/design/foundations/css-utilities/layout.
Screen.Recording.2023-02-27.at.21.15.18.mov

What should reviewers focus on?

Any alternatives? Was thinking we could also use a wrapper element that is shown with :focus-within. But adding a wrapper element makes things more complex and could mess up things like flexbox or so.

Can these changes ship as is?

  • Yes, this PR does not depend on additional changes. 🚢

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2023

🦋 Changeset detected

Latest commit: 0629fd0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/css Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

position: absolute;
width: 1px;
height: 1px;
margin: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed margin so negative margin can be used for positioning.

padding: 0 !important;
overflow: hidden !important;
clip: rect(1px, 1px, 1px, 1px) !important;
border: 0 !important;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added padding + border since they can increase the size of an element.

@github-actions github-actions bot temporarily deployed to Storybook Preview February 27, 2023 13:00 Inactive
@github-actions github-actions bot temporarily deployed to Storybook Preview February 27, 2023 13:04 Inactive
@simurai simurai marked this pull request as ready for review February 27, 2023 13:11
@simurai simurai requested a review from a team as a code owner February 27, 2023 13:11
@simurai simurai merged commit 95ab0d0 into main Feb 28, 2023
@simurai simurai deleted the show-on-focus branch February 28, 2023 06:00
@primer-css primer-css mentioned this pull request Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants