Skip to content

Commit

Permalink
Conform to Selectors API and put more onus on block author
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Sep 15, 2023
1 parent 7392d7b commit 9596eb7
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions packages/block-library/src/navigation-link/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ function render_block_core_navigation_link( $attributes, $content, $block ) {
// Determine the logic that maps to the concept of "current item".
$is_active = ! empty( $attributes['id'] ) && get_queried_object_id() === (int) $attributes['id'] && ! empty( get_queried_object()->$kind );

$block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'core/navigation' );

// TODO - handle converting CSS selector to classname.
$current_item_classname = isset( $block_type->selectors['@currentItem'] ) ? str_replace( '.', '', $block_type->selectors['@currentItem'] ) : 'current-menu-item';
// Must match @currentItem in block.json.
$current_item_classname = 'current-menu-item';

$wrapper_attributes = get_block_wrapper_attributes(
array(
Expand Down
2 changes: 1 addition & 1 deletion packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"interactivity": true
},
"selectors": {
"@currentItem": ".current-menu-item"
"@currentItem": ".wp-block-navigation .current-menu-item"
},
"viewScript": "file:./view.min.js",
"editorStyle": "wp-block-navigation-editor",
Expand Down
2 changes: 1 addition & 1 deletion phpunit/class-wp-theme-json-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -2281,7 +2281,7 @@ public function test_get_stylesheet_allows_current_item() {
// TODO: Make this a global for the entire test.
$base_styles = 'body { margin: 0;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){max-width: var(--wp--style--global--content-size);margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignwide{max-width: var(--wp--style--global--wide-size);}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}';

$expected = '.wp-block-navigation{background-color: red;color: green;}.wp-block-navigation .current-item{background-color: '. $expected_background_value .';color: ' . $expected_text_value . ';}';
$expected = '.wp-block-navigation{background-color: red;color: green;}.wp-block-navigation .current-menu-item{background-color: '. $expected_background_value .';color: ' . $expected_text_value . ';}';

Check failure on line 2284 in phpunit/class-wp-theme-json-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Concat operator must be surrounded by a single space

Check failure on line 2284 in phpunit/class-wp-theme-json-test.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Concat operator must be surrounded by a single space

$generated = $theme_json->get_stylesheet();

Expand Down

0 comments on commit 9596eb7

Please sign in to comment.