Skip to content

Commit

Permalink
Prevent .show-on-focus to change width/height (#2391)
Browse files Browse the repository at this point in the history
* Update `.show-on-focus` to not reset width/height

* Add `ShowOnFocus` story

* Create .changeset/shy-pumpkins-walk.md
  • Loading branch information
simurai authored Feb 28, 2023
1 parent 5dc4fea commit 95ab0d0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-pumpkins-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/css": patch
---

Prevent `.show-on-focus` to change width/height
7 changes: 7 additions & 0 deletions docs/src/stories/utilities/Layout.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ export const ScreenReaderOnly = ({}) => (
</div>
)

export const ShowOnFocus = ({}) => (
<div>
<div class="mb-2">Click here and press tab to make the ".show-on-focus" element appear</div>
<button type="button" class="btn show-on-focus">.show-on-focus</button>
</div>
)

export const MediaObject = ({}) => (
<div class="clearfix p-3 border">
<div class="float-left p-3 mr-3 color-bg-subtle">
Expand Down
19 changes: 10 additions & 9 deletions src/utilities/visibility-display.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,18 @@

// Only display content on focus
.show-on-focus {
position: absolute;
width: 1px;
height: 1px;
margin: 0;
overflow: hidden;
clip: rect(1px, 1px, 1px, 1px);
position: absolute !important;

&:not(:focus) {
width: 1px !important;
height: 1px !important;
padding: 0 !important;
overflow: hidden !important;
clip: rect(1px, 1px, 1px, 1px) !important;
border: 0 !important;
}

&:focus {
z-index: 999;
width: auto;
height: auto;
clip: auto;
}
}

0 comments on commit 95ab0d0

Please sign in to comment.