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

Use a pseudo element to prevent inspector tab width from changing when selected #9793

Merged
merged 5 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions edit-post/components/sidebar/settings-header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import SidebarHeader from '../sidebar-header';

const SettingsHeader = ( { count, openDocumentSettings, openBlockSettings, sidebarName } ) => {
// Do not display "0 Blocks".
count = count === 0 ? 1 : count;
const blockCount = count === 0 ? 1 : count;
const blockLabel = blockCount === 1 ?
__( 'Block' ) :
sprintf( _n( '%d Block', '%d Blocks', blockCount ), blockCount );

return (
<SidebarHeader
Expand All @@ -24,19 +27,17 @@ const SettingsHeader = ( { count, openDocumentSettings, openBlockSettings, sideb
onClick={ openDocumentSettings }
className={ `edit-post-sidebar__panel-tab ${ sidebarName === 'edit-post/document' ? 'is-active' : '' }` }
aria-label={ __( 'Document settings' ) }
data-label={ __( 'Document' ) }
>
{ __( 'Document' ) }
</button>
<button
onClick={ openBlockSettings }
className={ `edit-post-sidebar__panel-tab ${ sidebarName === 'edit-post/block' ? 'is-active' : '' }` }
aria-label={ __( 'Block settings' ) }
data-label={ blockLabel }
>
{ (
1 === count ?
__( 'Block' ) :
sprintf( _n( '%d Block', '%d Blocks', count ), count )
) }
{ blockLabel }
</button>
</SidebarHeader>
);
Expand Down
13 changes: 13 additions & 0 deletions edit-post/components/sidebar/settings-header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
color: $dark-gray-900;
@include square-style__neutral;

// This pseudo-element "duplicates" the tab label and sets the text to bold.
// This ensures that the tab doesn't change width when selected.
Copy link
Member

Choose a reason for hiding this comment

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

Good description; I'll add a link to this PR (just in case git blame eventually doesn't lead someone back to here) for context.

// See: https://github.com/WordPress/gutenberg/pull/9793
&::after {
content: attr(data-label);
display: block;
font-weight: 600;
height: 0;
overflow: hidden;
speak: none;
visibility: hidden;
}

&.is-active {
padding-bottom: 0;
border-bottom: 3px solid theme(primary);
Expand Down