Skip to content

Commit

Permalink
Allow :focus-visible pseudo-selector to be set in theme.json
Browse files Browse the repository at this point in the history
  • Loading branch information
huubl committed Jan 7, 2025
1 parent 3e6a5e4 commit daf6aae
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/how-to-guides/themes/global-settings-and-styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ h3 {
{% end %}
##### Element pseudo selectors

Pseudo selectors `:hover`, `:focus`, `:visited`, `:active`, `:link`, `:any-link` are supported by Gutenberg.
Pseudo selectors `:hover`, `:focus`, `:focus-visible`, `:visited`, `:active`, `:link`, `:any-link` are supported by Gutenberg.

```json
"elements": {
Expand Down
7 changes: 4 additions & 3 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ class WP_Theme_JSON_Gutenberg {
/**
* Defines which pseudo selectors are enabled for which elements.
*
* The order of the selectors should be: link, any-link, visited, hover, focus, active.
* The order of the selectors should be: link, any-link, visited, hover, focus, focus-visible, active.
* This is to ensure the user action (hover, focus and active) styles have a higher
* specificity than the visited styles, which in turn have a higher specificity than
* the unvisited styles.
Expand All @@ -573,10 +573,11 @@ class WP_Theme_JSON_Gutenberg {
*
* @since 6.1.0
* @since 6.2.0 Added support for `:link` and `:any-link`.
* @since 6.8.0 Added support for `:focus-visible`.
*/
const VALID_ELEMENT_PSEUDO_SELECTORS = array(
'link' => array( ':link', ':any-link', ':visited', ':hover', ':focus', ':active' ),
'button' => array( ':link', ':any-link', ':visited', ':hover', ':focus', ':active' ),
'link' => array( ':link', ':any-link', ':visited', ':hover', ':focus', ':focus-visible', ':active' ),
'button' => array( ':link', ':any-link', ':visited', ':hover', ':focus', ':focus-visible', ':active' ),
);

/**
Expand Down
5 changes: 5 additions & 0 deletions schemas/json/theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -1703,6 +1703,7 @@
},
"stylesElementsPseudoSelectorsProperties": {
"type": "object",
"properties": {
"properties": {
":active": {
"$ref": "#/definitions/stylesPropertiesComplete"
Expand All @@ -1713,6 +1714,9 @@
":focus": {
"$ref": "#/definitions/stylesPropertiesComplete"
},
":focus-visible": {
"$ref": "#/definitions/stylesPropertiesComplete"
},
":hover": {
"$ref": "#/definitions/stylesPropertiesComplete"
},
Expand All @@ -1729,6 +1733,7 @@
":active",
":any-link",
":focus",
":focus-visible",
":hover",
":link",
":visited"
Expand Down

0 comments on commit daf6aae

Please sign in to comment.