Make WordPress Core


Ignore:
Timestamp:
07/18/2024 06:41:29 AM (6 months ago)
Author:
noisysocks
Message:

Block Themes: Avoid specificity bump for top-level element-only selectors

Prevent issues (e.g. links being underlined) caused by a bump in CSS
specificity for top-level element-only global element styles.

Backports the PHP changes from https://github.com/WordPress/gutenberg/pull/63403.

Fixes #61630.
Fixes #61660.
Props aaronrobertshaw, andrewserong, noisysocks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r58703 r58749  
    28892889        }
    28902890
     2891        /*
     2892         * Top-level element styles using element-only specificity selectors should
     2893         * not get wrapped in `:root :where()` to maintain backwards compatibility.
     2894         *
     2895         * Pseudo classes, e.g. :hover, :focus etc., are a class-level selector so
     2896         * still need to be wrapped in `:root :where` to cap specificity for nested
     2897         * variations etc. Pseudo selectors won't match the ELEMENTS selector exactly.
     2898         */
     2899        $element_only_selector = $current_element &&
     2900            isset( static::ELEMENTS[ $current_element ] ) &&
     2901            // buttons, captions etc. still need `:root :where()` as they are class based selectors.
     2902            ! isset( static::__EXPERIMENTAL_ELEMENT_CLASS_NAMES[ $current_element ] ) &&
     2903            static::ELEMENTS[ $current_element ] === $selector;
     2904
    28912905        // 2. Generate and append the rules that use the general selector.
    2892         $block_rules .= static::to_ruleset( ":root :where($selector)", $declarations );
     2906        $general_selector = $element_only_selector ? $selector : ":root :where($selector)";
     2907        $block_rules     .= static::to_ruleset( $general_selector, $declarations );
    28932908
    28942909        // 3. Generate and append the rules that use the duotone selector.
Note: See TracChangeset for help on using the changeset viewer.