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

Tabs: Try a simpler tab focus style, alt #46276

Merged
merged 7 commits into from
Dec 8, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 48 additions & 34 deletions packages/components/src/tab-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,57 +7,71 @@
}
}

// This tab style CSS is duplicated verbatim in
// /packages/edit-post/src/components/sidebar/settings-header/style.scss
.components-tab-panel__tabs-item {
position: relative;
border-radius: 0;
height: $grid-unit-60;
background: transparent;
border: none;
box-shadow: none;
border-radius: 0;
cursor: pointer;
height: $grid-unit-60;
padding: 3px $grid-unit-20; // Use padding to offset the is-active border, this benefits Windows High Contrast mode
margin-left: 0;
font-weight: 500;
transition: box-shadow 0.1s linear;
box-sizing: border-box;

// This pseudo-element "duplicates" the tab label and sets the text to bold.
// This ensures that the tab doesn't change width when selected.
// See: https://github.com/WordPress/gutenberg/pull/9793
&:focus:not(:disabled) {
position: relative;
z-index: z-index(".edit-post-sidebar__panel-tab.is-active");
Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand the purpose of all the z-index styles. Could you explain the intent?

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'm actually not sure — I know it was necessary at one point, but I think the tabs have been refactored enough that it might not be needed anymore. When I tried removing it just now, it worked fine without it. I'll try and remove it and see if that helps.

box-shadow: none;
}

// Tab indicator
&::after {
content: attr(data-label);
display: block;
height: 0;
overflow: hidden;
speak: none;
visibility: hidden;
content: "";
position: absolute;
z-index: z-index(".edit-post-sidebar__panel-tab.is-active");
right: 0;
bottom: 0;
left: 0;
pointer-events: none;

// Draw the indicator.
background: var(--wp-admin-theme-color);
jasmussen marked this conversation as resolved.
Show resolved Hide resolved
height: calc(0 * var(--wp-admin-border-width-focus));
border-radius: 0;

// Animation
transition: all 0.1s linear;
@include reduce-motion("transition");
}

&:focus:not(:disabled) {
box-shadow: inset 0 var(--wp-admin-border-width-focus) $components-color-accent;
// Active.
&.is-active::after {
height: calc(1 * var(--wp-admin-border-width-focus));
}

&.is-active {
// The transparent shadow ensures no jumpiness when focus animates on an active tab.
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) transparent, inset 0 0 -$border-width-tab 0 0 $components-color-accent;
position: relative;
// Focus.
&::before {
content: "";
position: absolute;
top: $grid-unit-15;
right: $grid-unit-15;
bottom: $grid-unit-15;
left: $grid-unit-15;
pointer-events: none;

// This border appears in Windows High Contrast mode instead of the box-shadow.
&::before {
content: "";
position: absolute;
top: 0;
bottom: 1px;
right: 0;
left: 0;
border-bottom: $border-width-tab solid transparent;
}
}
// Draw the indicator.
box-shadow: 0 0 0 0 transparent;
border-radius: $radius-block-ui;

&:focus {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent;
// Animation
transition: all 0.1s linear;
@include reduce-motion("transition");
}

&.is-active:focus {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent, inset 0 -#{$border-width-tab * 2} 0 0 $components-color-accent;
&:focus-visible::before {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
jasmussen marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,68 @@
// This tab style CSS is duplicated verbatim in
// /packages/components/src/tab-panel/style.scss
.components-button.edit-post-sidebar__panel-tab {
position: relative;
border-radius: 0;
height: $grid-unit-60;
background: transparent;
border: none;
box-shadow: none;
cursor: pointer;
display: inline-block;
padding: 3px 15px; // Use padding to offset the is-active border, this benefits Windows High Contrast mode
padding: 3px $grid-unit-20; // Use padding to offset the is-active border, this benefits Windows High Contrast mode
margin-left: 0;
font-weight: 500;

// This pseudo-element "duplicates" the tab label and sets the text to bold.
// This ensures that the tab doesn't change width when selected.
// 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;
&:focus:not(:disabled) {
position: relative;
z-index: z-index(".edit-post-sidebar__panel-tab.is-active");
box-shadow: none;
}

&.is-active {
// The transparent shadow ensures no jumpiness when focus animates on an active tab.
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) transparent, inset 0 0 -$border-width-tab 0 0 var(--wp-admin-theme-color);
position: relative;
// Tab indicator
&::after {
content: "";
position: absolute;
z-index: z-index(".edit-post-sidebar__panel-tab.is-active");
right: 0;
bottom: 0;
left: 0;
pointer-events: none;

// Draw the indicator.
background: var(--wp-admin-theme-color);
height: calc(0 * var(--wp-admin-border-width-focus));
border-radius: 0;

// This border appears in Windows High Contrast mode instead of the box-shadow.
&::before {
content: "";
position: absolute;
top: 0;
bottom: 1px;
right: 0;
left: 0;
border-bottom: $border-width-tab solid transparent;
}
// Animation
transition: all 0.1s linear;
@include reduce-motion("transition");
}

&:focus {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
position: relative;
z-index: z-index(".edit-post-sidebar__panel-tab.is-active");
// Active.
&.is-active::after {
height: calc(1 * var(--wp-admin-border-width-focus));
}

// Focus.
&::before {
content: "";
position: absolute;
top: $grid-unit-15;
right: $grid-unit-15;
bottom: $grid-unit-15;
left: $grid-unit-15;
pointer-events: none;

// Draw the indicator.
box-shadow: 0 0 0 0 transparent;
border-radius: $radius-block-ui;

// Animation
transition: all 0.1s linear;
@include reduce-motion("transition");
}

&.is-active:focus {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color), inset 0 -#{$border-width-tab * 2} 0 0 var(--wp-admin-theme-color);
&:focus-visible::before {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
}
}