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

Home link block: Add 'current-menu-item' #51478

Merged
merged 8 commits into from
Jul 19, 2023

Conversation

carolinan
Copy link
Contributor

@carolinan carolinan commented Jun 14, 2023

What?

Adds the CSS class 'current-menu-item' to the home link block.
Testing instructions were updated June 26.

Closes #34770

Why?

Adding the class makes the block easier to style. The class is already used in the page list block and the navigation link block, and this change makes it easier to style the current menu items consistently.

How?

Adds the CSS class, conditionally, to the <li> item in the block's index.php file.

Testing Instructions

Add a navigation block to a site-wide header template part. The important thing is that the menu item can be tested on the correct page to trigger the condition and add the CSS class.

Inside the navigation block, insert the Home link block.
View the homepage on the front of the website.
Confirm that the Home link block has the CSS class current-menu-item on the li element:
<li class="wp-block-navigation-item current-menu-item wp-block-home-link">
Open any link on the site that is not the homepage, and confirm that the Home menu item no longer has the current-menu-item class.

There are two edge cases, and that is when the user adds the assigned "posts page" and or the homepage from the Reading settings to the navigation block, besides the home link block. In this case, the class name as well as the aria-current attribute, will be duplicated.
I think this needs to be considered a user error, adding the same link more than once.

@carolinan carolinan marked this pull request as ready for review June 14, 2023 07:33
@carolinan carolinan requested a review from ajitbohra as a code owner June 14, 2023 07:33
@carolinan carolinan added [Block] Home Link Affects the Home Link Block [Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement. labels Jun 14, 2023
Copy link
Contributor

@alexstine alexstine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carolinan One question below. Also, checks are in a weird state. Needs refresh?

packages/block-library/src/home-link/index.php Outdated Show resolved Hide resolved
@github-actions
Copy link

github-actions bot commented Jun 26, 2023

Flaky tests detected in 4eb1a23.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5517782322
📝 Reported issues:

Copy link
Member

@aristath aristath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how we missed this when initially adding the current-menu-item classes...
Good catch @carolinan, thank you for working on this!

Approving this one, it's good to merge 👍

@aristath aristath enabled auto-merge (squash) July 19, 2023 08:20
@aristath aristath merged commit d27c43f into trunk Jul 19, 2023
@aristath aristath deleted the add/home-link-current-menu-item branch July 19, 2023 08:53
@github-actions github-actions bot added this to the Gutenberg 16.3 milestone Jul 19, 2023
@getdave
Copy link
Contributor

getdave commented Jul 19, 2023

Thank you both. This is so great to see! 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Home Link Affects the Home Link Block [Block] Navigation Affects the Navigation Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Home link block doesn't use current-menu-item class when on front page
4 participants