Make WordPress Core


Ignore:
Timestamp:
01/20/2021 05:49:28 AM (3 years ago)
Author:
SergeyBiryukov
Message:

Twenty Twenty-One: Clean up Button styles.

This change restructures the Button element styles for better a11y and expected color behaviors. Here what has changed:

  • The button-style() mixin is now the single source or truth for how Button should look site-wide.
    • Button Block, File Block, and Search form Blocks all rely on this one mixin.
    • The same styles is also applied to the <button> element which appears in widgets, the 404 search form and comments form.
  • Improves expected button styles for various conditions and contexts as follows:
    • User color palette selections for Buttons are retained regardless of a parent block’s color settings or dark-mode.
    • Supports both Default/Filled styles and Outline styles.
    • More consistent :hover and :active styles.
    • :focus styles are now always visible and legible.
  • Adds a --local-color color variable to scope color relationships to nested blocks.
  • Reduces selectors in style.css output.
  • 1:1 experience between editor and front end button styles.
  • Properly supports Dark-mode.

Props allancole, poena, scruffian, megphillips91.
Fixes #51927.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentyone/assets/sass/05-blocks/button/_style.scss

    r49574 r49987  
    55input[type="submit"],
    66input[type="reset"],
    7 .wp-block-search__button,
    8 .wp-block-button .wp-block-button__link {
     7.wp-block-search .wp-block-search__button,
     8.wp-block-button .wp-block-button__link,
     9.wp-block-file a.wp-block-file__button {
    910    // Extend button style
    1011    @include button-style();
    11 }
    12 
    13 .site .button,
    14 input[type="submit"],
    15 input[type="reset"],
    16 .wp-block-search .wp-block-search__button,
    17 .wp-block-file .wp-block-file__button {
    18 
    19     &:active {
    20         color: var(--button--color-text-active);
    21         background-color: var(--button--color-background-active);
    22     }
    23 
    24     &:hover {
    25         color: var(--button--color-text-hover);
    26         background: transparent;
    27     }
    2812}
    2913
     
    3620    &:not(.is-style-outline) {
    3721
    38         .wp-block-button__link {
     22        .wp-block-button__link:not(:hover):not(:active) {
    3923
    40             &:active {
    41                 color: var(--button--color-text-active) !important;
    42                 background: transparent !important;
    43                 border-color: var(--button--color-background);
     24            // Text colors
     25            &:not(.has-text-color) {
     26                color: var(--global--color-background);
     27
     28                // Nested
     29                .has-background & {
     30                    color: var(--local--color-background, var(--global--color-background));
     31
     32                    &.has-background {
     33                        color: var(--global--color-primary);
     34                    }
     35                }
    4436            }
    4537
    46             &:hover {
    47                 color: var(--button--color-text-hover) !important;
    48                 background: transparent !important;
    49                 border-color: var(--button--color-background);
     38            // Background-colors
     39            &:not(.has-background) {
     40                background-color: var(--global--color-primary);
     41
     42                // Nested
     43                .has-background & {
     44                    background-color: var(--local--color-primary, var(--global--color-primary));
     45                }
    5046            }
     47        }
    5148
    52             &:focus {
    53                 color: var(--button--color-text) !important;
    54                 background: var(--button--color-background) !important;
    55             }
     49        // Hover Button color should match parent element foreground color
     50        .wp-block-button__link:hover,
     51        .wp-block-button__link:active {
     52            border-color: currentColor !important;
     53            background-color: transparent !important;
     54            color: inherit !important;
    5655        }
    5756    }
     
    6059    &.is-style-outline {
    6160
    62         .wp-block-button__link {
    63             padding: var(--button--padding-vertical) var(--button--padding-horizontal);
     61        .wp-block-button__link:not(:hover):not(:active) {
    6462
    65             &:not(.has-background) {
    66                 background: transparent;
     63            // Border colors
     64            &:not(.has-text-color),
     65            &:not(.has-background),
     66            &.has-background {
     67                border-color: currentColor;
    6768            }
    6869
    69             &:not(.has-background):not(.has-text-color) {
    70                 background: transparent;
    71                 color: var(--button--color-background);
    72                 border-color: var(--button--color-background);
    73             }
     70            // Text colors
     71            &:not(.has-text-color) {
     72                color: var(--global--color-primary);
    7473
    75             &.has-background:not(.has-text-color) {
    76                 color: currentColor;
    77             }
    78 
    79             &.has-background.has-gray-background-color:not(.has-text-color),
    80             &.has-background.has-dark-gray-background-color:not(.has-text-color),
    81             &.has-background.has-black-background-color:not(.has-text-color) {
    82                 color: var(--global--color-white);
    83             }
    84 
    85             .is-dark-theme & {
    86 
    87                 &:not(.has-text-color) {
    88 
    89                     &.has-background {
    90                         color: var(--global--color-dark-gray);
    91                     }
    92 
    93                     &.has-background.has-gray-background-color,
    94                     &.has-background.has-dark-gray-background-color,
    95                     &.has-background.has-black-background-color {
    96                         color: var(--global--color-white);
    97                     }
     74                // Nested
     75                .has-background & {
     76                    color: var(--local--color-primary, var(--global--color-primary));
    9877                }
    9978            }
    10079
    101             &.has-text-color,
    102             &.has-background.has-text-color {
    103                 border-color: currentColor;
    104             }
    105 
    106             &:active,
    107             &:hover {
    108                 color: var(--button--color-text) !important;
    109                 background: var(--button--color-background) !important;
    110                 border-color: var(--button--color-background);
    111 
    112                 &.has-text-color {
    113                     border-color: var(--button--color-background);
     80            &.has-background {
     81                // Nested
     82                .has-background &:not(.has-text-color) {
     83                    color: inherit;
    11484                }
    11585            }
    11686
    117             &:focus {
    118                 color: var(--button--color-background) !important;
    119                 background: transparent !important;
     87            // Background-colors
     88            &:not(.has-background) {
     89                background-color: transparent;
     90            }
     91        }
     92
     93        .wp-block-button__link:hover,
     94        .wp-block-button__link:active {
     95
     96            border-color: transparent !important;
     97            background-color: var(--global--color-primary) !important;
     98            color: var(--global--color-background) !important;
     99
     100            .has-background & {
     101                background-color: var(--local--color-primary, var(--global--color-primary)) !important;
     102                color: var(--local--color-background, var(--global--color-background)) !important;
     103            }
     104
     105            .has-text-color & {
     106                color: var(--local--color-background, var(--global--color-background)) !important;
    120107            }
    121108        }
Note: See TracChangeset for help on using the changeset viewer.