Skip to content

feat[my-account-block]: add option to toggle off icon/text, and update tests#4443

Open
laurelfulford wants to merge 6 commits intotrunkfrom
feat/my-account-button-display
Open

feat[my-account-block]: add option to toggle off icon/text, and update tests#4443
laurelfulford wants to merge 6 commits intotrunkfrom
feat/my-account-button-display

Conversation

@laurelfulford
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

This PR adds an option to hide either the icon or label on the My Account Button block (but not both at the same time).

As part of that, I changed how the button acts if you don't give it a text label (instead of not showing anything, it will fallback to the default labels) -- when it's hidden in the settings, the label is still used as screen reader text so we don't want it to be empty even if it's not visible.

I also updated the tests to check for the default (vs. making sure empty strings were empty), and tweaked the behaviour to make sure logged in admins (not just readers) would see the My Account labels - I thought this was working before but I was seeing Sign In in trunk.

See NPPD-1183.

How to test the changes in this Pull Request:

  1. Apply this PR and run npm run build. As a bonus you can also test this alongside feat: make My Account button only show icon on mobile newspack-block-theme#406, but it's not required.
  2. If using the default header patterns, the button should already be in the header. If not, add the My Account Button block to the header.
  3. Click on the button and confirm you have a Display panel under the Settings tab, with an option to Display label and Display icon. Both should be enabled by default:
CleanShot 2026-02-02 at 10 48 31@2x
  1. Try turning of each option and confirm that the button updates appropriately (hiding the text or the icon). Confirm that you can't turn off both options at once -- if you try to turn off say, the icon, the label should switch to visible if it isn't already, and vis versa.
  2. Try changing the text labels on each state of the button (Signed in, Signed out), turn off the Show label toggle, and view on the front end.
  3. Confirm you only see the icons; when you inspect the icon, you should see your label text wrapped in a screen-reader-text span.
  4. Try signing in/signing up in an incognito window, and confirm hidden text is right (that you can see the Signed out text in the markup when you're not logged in, and Signed in text when you are).
  5. Try editing the header again and switching the settings so you can see the text, but not the icon; repeat step 7.
  6. Try editing the text label of each button and leave it blank; confirm you can still see the placeholder in the editor.
  7. Publish your changes and confirm you see the default text on the front-end (Sign In and My Account).
  8. Run the tests just to make sure they come back okay.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds display controls to the My Account Button block, allowing users to selectively hide either the icon or label text, while ensuring at least one element remains visible for usability. The PR also improves the empty label fallback behavior and fixes an issue where logged-in admins were seeing incorrect button labels.

Changes:

  • Added showLabel and showIcon boolean attributes with UI toggles in the Inspector Controls
  • Updated empty label handling to fallback to defaults instead of rendering nothing
  • Added data-wp-logged-in attribute to preserve correct labels for logged-in WordPress users
  • Updated tests to verify fallback behavior for empty labels

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/blocks/my-account-button/block.json Added showLabel and showIcon boolean attributes with default values of true
src/blocks/my-account-button/edit.js Implemented Inspector Controls with toggle controls and mutual exclusivity logic, added conditional rendering for icon/label visibility
src/blocks/my-account-button/class-my-account-button-block.php Added showLabel/showIcon attribute handling, conditional rendering logic, screen-reader-text class for hidden labels, and data-wp-logged-in attribute
src/reader-activation-auth/index.js Added check for logged-in WordPress users to preserve correct label text and prevent unnecessary reader authentication checks
tests/unit-tests/class-test-my-account-button-block.php Split empty label test into separate signed-in/signed-out tests, updated assertions to verify fallback to default labels
src/blocks/my-account-button/README.md Added documentation for the new Display toggle feature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thomasguillot thomasguillot force-pushed the feat/my-account-button-display branch from 8d2f75a to 666a61a Compare February 3, 2026 18:02
@thomasguillot thomasguillot force-pushed the feat/my-account-button-display branch from 666a61a to d315db9 Compare February 3, 2026 18:04
@Automattic Automattic deleted a comment from laurelfulford Feb 3, 2026
@thomasguillot
Copy link
Contributor

thomasguillot commented Feb 3, 2026

Here's an update, using styles: d315db9

image

@laurelfulford
Copy link
Contributor Author

@thomasguillot Looks good to me! 🙂 Now we just need to see what an uninvolved third-party has to say!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Needs Design Review [Status] Needs Review The issue or pull request needs to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants