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

The editor should not allow to save empty navigation links #59560

Open
afercia opened this issue Mar 4, 2024 · 3 comments
Open

The editor should not allow to save empty navigation links #59560

afercia opened this issue Mar 4, 2024 · 3 comments
Labels
[Block] Navigation Link Affects the Navigation Link Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended

Comments

@afercia
Copy link
Contributor

afercia commented Mar 4, 2024

Description

Discovered while working on #59370

Empty navigation links are less than ideal for accessibility and SEO.
The editor actually allows to save and render on the front end an empty link by leaving the navigation link label empty or by entering spaces. Worth noting the classic menu items work differently, for good reasons:

  • A nenu item with empty label is not saved.
  • A menu item with label made only of spaces is saved but in the front end a link text fallback is printed out: 'Untitled'.

Step-by-step reproduction instructions

  • Go to the site editor and edit a navigation menu.
  • Select a navigation link, empty its label and save.
  • Observe savign is successful: no warnings or any ohter feedback about the empty link.
  • Go to the front end and observe the link text is empty.
  • In the editor, open the navigation panel and observe the list view displays only an icon for the empty link. This should be mitigated by Fix labeling of the navigation links in the list view. #59370

Screenshots, screen recording, code snippet

In the editor: an empty link doesn't have any fallback label in the list view:

Screenshot 2024-03-04 at 16 44 48

On the front end, the link is empty and bareli visible. Only when focused it shows the focus style:

Screenshot 2024-03-04 at 16 54 24

With classic menus, a link that only contains spaces is saved even though there's no label shown in the admin:

Screenshot 2024-03-04 at 12 03 42

On the fron tend, classic menus do use a fallback text 'Untitled' for empty links:

Screenshot 2024-03-04 at 12 03 58

Environment info

No response

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@afercia afercia added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block editor /packages/block-editor [Block] Navigation Link Affects the Navigation Link Block labels Mar 4, 2024
@afercia
Copy link
Contributor Author

afercia commented Mar 8, 2024

I noticed this is similar to empty headings as well.

To recap:

LInks

It is possible to save a navigation link with a URL but with the label that only contains spaces. In this case, link is rendered on the fron tend with:

  • the label that contains the spaces
  • the hres attribute ie empty even though the value is saved in the editor

Rendered markup example:

<a class="wp-block-navigation-item__content" href="">
    <span class="wp-block-navigation-item__label">  </span>
</a>

This should be avoided entirely. No markup should be rendered for an empty link.

Headings

It is possible to save a Heading that is entirely empty (even without spaces). In this case, the rendered HTML is:

<h2 class="wp-block-heading"></h2>

This should be avoided entirely. No markup should be rendered for an empty heading.

I think the two problems are related as they both come from way a block content / label is retrieved.

  • The inconsistency with sapces should be addressed. Ideally, all content strings should be trimmed and checked if empty after that.
  • For all blocks: no HTML should be ever rendered when the block content is empty.

@krokodok
Copy link
Contributor

For all blocks: no HTML should be ever rendered when the block content is empty.

What about blocks that don't have content, like the spacer?

Or what if I add an empty group with background color and height and / or padding? I think it would be confusing to the users, if this empty group would not show up visually.

@afercia
Copy link
Contributor Author

afercia commented Jul 23, 2024

@krokodok thanks for pointing out I was not very clear. I will rephrase:

For all blocks that are supposed to render some content: no HTML should be ever rendered when the block content is empty.

Besides that, I would argue the Spacer block is using HTML for presentational purposes, which brings us back to the era of the HTML soup where the HTML was full of presentational elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Link Affects the Navigation Link Block [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Package] Block editor /packages/block-editor [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

2 participants