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

Try improving and standardizing the block styles focus + active states #16545

Merged
merged 2 commits into from
Jul 12, 2019
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
22 changes: 20 additions & 2 deletions assets/stylesheets/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,33 @@
color: $dark-gray-900;
}

@mixin block-style__focus-active() {
@mixin block-style__focus() {
color: $dark-gray-900;
box-shadow: 0 0 0 2px $blue-medium-500;
box-shadow: 0 0 0 1px $white, 0 0 0 3px $blue-medium-500;

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
outline-offset: -2px;
}

@mixin block-style__is-active() {
color: $dark-gray-900;
box-shadow: inset 0 0 0 2px $dark-gray-500;

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 2px solid transparent;
outline-offset: -2px;
}

@mixin block-style__is-active-focus() {
color: $dark-gray-900;
box-shadow: 0 0 0 1px $white, 0 0 0 3px $blue-medium-500, inset 0 0 0 2px $dark-gray-500;

// Windows High Contrast mode will show this outline, but not the box-shadow.
outline: 4px solid transparent;
outline-offset: -4px;
}

/**
* Applies editor left position to the selector passed as argument
*/
Expand Down
17 changes: 10 additions & 7 deletions packages/block-editor/src/components/block-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
cursor: pointer;
overflow: hidden;
border-radius: $radius-round-rectangle;
padding: $grid-size-small;

&.is-active {
@include block-style__focus-active();
box-shadow: 0 0 0 2px $dark-gray-500;
}
padding: $grid-size-small * 1.5;

&:focus {
@include block-style__focus-active();
@include block-style__focus();
}

&:hover {
@include block-style__hover;
}

&.is-active {
@include block-style__is-active();

&:focus {
@include block-style__is-active-focus();
}
}
}

.block-editor-block-styles__item-preview {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.block-editor-block-types-list {
list-style: none;
padding: 2px 0;
padding: 4px 0;
overflow: hidden;
display: flex;
flex-wrap: wrap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,26 @@
}

&:active,
&.is-active,
&:focus {
position: relative;

// Show the focus style in the icon inside instead.
outline: none;
@include block-style__focus-active();
@include block-style__focus();

.block-editor-block-types-list__item-icon,
.block-editor-block-types-list__item-title {
color: inherit;
}
}

&.is-active {
@include block-style__is-active();

&:focus {
@include block-style__is-active-focus();
}
}
}
}

Expand Down