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鈥檒l 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
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
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.

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;
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.

}

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