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

added structured data markup and aria labels to site navigation #3539

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions resources/js/src/app/components/pageDesign/MobileNavigation.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<template>
<div class="mobile-navigation" :class="{ 'open': isMobileNavigationOpen }">
<div class="mobile-navigation" :class="{ 'open': isMobileNavigationOpen }" id="mobile-navigation-wrapper"
aria-labelledby="mobile-navigation-toggler" itemscope itemtype="https://schema.org/SiteNavigationElement" role="menu">
Comment on lines +2 to +3
Copy link
Contributor

Choose a reason for hiding this comment

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

According to ARIA best practices, role="menu" should typically be used for desktop applications menus, not for website navigation.

For website navigation role="navigation" or native <nav> is more appropriate.

Suggested change
<div class="mobile-navigation" :class="{ 'open': isMobileNavigationOpen }" id="mobile-navigation-wrapper"
aria-labelledby="mobile-navigation-toggler" itemscope itemtype="https://schema.org/SiteNavigationElement" role="menu">
<div class="mobile-navigation" :class="{ 'open': isMobileNavigationOpen }" id="mobile-navigation-wrapper"
aria-labelledby="mobile-navigation-toggler" itemscope itemtype="https://schema.org/SiteNavigationElement" role="navigation">

<div v-show="isNavigationInitialized">
<ul class="breadcrumb d-block px-3 py-0">
<li class="btn-close" @click="closeNavigation()"></li>
<li class="btn-close" @click="closeNavigation()" :aria-label="$translate('Ceres::Template.closeIcon')"></li>

<li class="breadcrumb-item" @click="slideTo(null, true)">
<i class="fa fa-home" aria-hidden="true"></i>
Expand All @@ -20,7 +21,7 @@
</li>

<li class="ddown" v-for="category in dataContainer1.categories">
<a :href="getCategoryUrl(category.url)">{{ category.details[0].name }}</a>
<a :href="getCategoryUrl(category.url)" itemprop="name" role="menuitem">{{ category.details[0].name }}</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

If we change the role to navigation we don't need to set the role to the child anymore, as links with navigation have the implicit roles of "link" which is correct semantic role for navigation items.

Suggested change
<a :href="getCategoryUrl(category.url)" itemprop="name" role="menuitem">{{ category.details[0].name }}</a>
<a :href="getCategoryUrl(category.url)" itemprop="name">{{ category.details[0].name }}</a>

<span class="nav-direction" v-if="category.childCount" @click="slideTo(category)">
<i class="fa fa-lg fa-caret-right" aria-hidden="true"></i>
</span>
Expand All @@ -45,7 +46,7 @@
</li>

<li class="ddown" v-for="category in dataContainer2.categories">
<a :href="getCategoryUrl(category.url)">{{ category.details[0].name }}</a>
<a :href="getCategoryUrl(category.url)" itemprop="name" role="menuitem">{{ category.details[0].name }}</a>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<a :href="getCategoryUrl(category.url)" itemprop="name" role="menuitem">{{ category.details[0].name }}</a>
<a :href="getCategoryUrl(category.url)" itemprop="name">{{ category.details[0].name }}</a>

<span class="nav-direction" v-if="category.childCount" @click="slideTo(category)">
<i class="fa fa-lg fa-caret-right" aria-hidden="true"></i>
</span>
Expand All @@ -65,7 +66,7 @@

<template v-if="!isNavigationInitialized">
<ul class="breadcrumb">
<li class="btn-close" @click="closeNavigation()"></li>
<li class="btn-close" @click="closeNavigation()" :aria-label="$translate('Ceres::Template.closeIcon')"></li>

<li class="breadcrumb-item">
<i class="fa fa-home" aria-hidden="true"></i>
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/de/Template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ myAccountSave = "Speichern"
myAccountSettings = "Kontoeinstellungen"
myAccountShippingAddresses = "Lieferadressen"
; myAccount - My account
; navigation
menuLabel = "Menü"
doproiescu-plenty marked this conversation as resolved.
Show resolved Hide resolved
; navigation
; pageNotFound - Nicht gefunden
pageNotFoundHomepage = "Startseite"
pageNotFoundOops = "Ups, ein Fehler!"
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en/Template.properties
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ myAccountSave = "Save"
myAccountSettings = "Account settings"
myAccountShippingAddresses = "Delivery addresses"
; myAccount - My account
; navigation
menuLabel = "Menu"
doproiescu-plenty marked this conversation as resolved.
Show resolved Hide resolved
; navigation
; pageNotFound - Not found
pageNotFoundHomepage = "Homepage"
pageNotFoundOops = "Oops, something went terribly wrong!"
Expand Down
26 changes: 17 additions & 9 deletions resources/views/Category/Macros/CategoryTree.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
{% for child in category.children if counter < maxItems[level] %}
{% if (child.details | length > 0) %}
{% if level == 1 %}
<li><ul class="collapse-inner">
<li role="presentation"><ul class="collapse-inner">
Copy link
Contributor

Choose a reason for hiding this comment

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

role="presentation" is unnecessary in navigation context

Suggested change
<li role="presentation"><ul class="collapse-inner">
<li><ul class="collapse-inner">

{% endif %}
<li class="level{{ level }}">
{% set newScope = currentScopeUrl ~ "/" ~ child.details[0].nameUrl %}
<a @touchstart.stop href="{{ newScope }}{{ urls.trailingSlashSuffix }}">{{ child.details[0].name }}</a>
<a @touchstart.stop href="{{ newScope }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<a @touchstart.stop href="{{ newScope }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
<a @touchstart.stop href="{{ newScope }}{{ urls.trailingSlashSuffix }}" itemprop="name">

{{ child.details[0].name }}
</a>
</li>
{% if child.children %}
{{ childlist.get_children(child, newScope, level + 1, megaMenuLevels, maxItems) }}
Expand Down Expand Up @@ -49,18 +51,22 @@

{% if category.children and translatedChildren > 0 %}

<li {% if maxItemsPerStage[1] > 0 %}class="ddown"{% endif %} v-navigation-touch-handler>
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}">{{ category.details[0].name }}</a>
<li {% if maxItemsPerStage[1] > 0 %}class="ddown"{% endif %} v-navigation-touch-handler role="presentation">
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name">

{{ category.details[0].name }}
</a>
{% if maxItemsPerStage[1] > 0 %}
<ul data-level="1" class="collapse nav-dropdown-{{ counter }}">
<ul data-level="1" class="collapse nav-dropdown-{{ counter }}" role="menu" aria-label="{{ category.details[0].name }}">
{% set counter = counter + 1 %}
{% if megaMenuLevels == 1 %}
{% for child in category.children %}
{% if child.details | length > 0 %}
<li>
<li role="presentation">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<li role="presentation">
<li>

<ul class="collapse-inner">
<li>
<a href="{{ currentScopeUrl }}/{{ child.details[0].nameUrl }}{{ urls.trailingSlashSuffix }}">{{ child.details[0].name }}</a>
<a href="{{ currentScopeUrl }}/{{ child.details[0].nameUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<a href="{{ currentScopeUrl }}/{{ child.details[0].nameUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
<a href="{{ currentScopeUrl }}/{{ child.details[0].nameUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name">

{{ child.details[0].name }}
</a>
</li>
</ul>
</li>
Expand All @@ -75,8 +81,10 @@

{% else %}

<li>
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}">{{ category.details[0].name }}</a>
<li role="presentation">
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
{{ category.details[0].name }}
</a>
</li>
Comment on lines +84 to 88
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
<li role="presentation">
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name" role="menuitem">
{{ category.details[0].name }}
</a>
</li>
<li>
<a href="{{ currentScopeUrl }}{{ urls.trailingSlashSuffix }}" itemprop="name">
{{ category.details[0].name }}
</a>
</li>


{% endif %}
Expand Down
8 changes: 7 additions & 1 deletion resources/views/PageDesign/Partials/Header/Navigation.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
<img alt="{{ companyName }}" src="{{ companyLogo }}" class="img-fluid" />
</a>
{% endif %}
<button v-open-mobile-navigation class="navbar-toggler d-lg-none p-3" type="button">
<button v-open-mobile-navigation
class="navbar-toggler d-lg-none p-3"
type="button"
Copy link
Contributor

@Tim-M-S Tim-M-S Aug 9, 2024

Choose a reason for hiding this comment

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

Suggested change
type="button"
type="menu"

Wouldn't type="menu" be more accurate here?
https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement#htmlbuttonelement.type

id="mobile-navigation-toggler"
for="mobile-navigation-wrapper"
Copy link
Contributor

@Tim-M-S Tim-M-S Aug 9, 2024

Choose a reason for hiding this comment

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

Suggested change
for="mobile-navigation-wrapper"

I don't think the for attribute is allowed on anything besides <label> and <output>
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/for

aria-controls="menu"
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this only work if there was an interactive element with id="menu" ?
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-controls

aria-label="{{ trans("Ceres::Template.menuLabel") }}">
&#9776;
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% import "Ceres::Category.Macros.CategoryTree" as Tree %}

<ul class="mainmenu p-0 m-0 d-flex">
<ul class="mainmenu p-0 m-0 d-flex" itemscope itemtype="https://schema.org/SiteNavigationElement" role="menu">
{{ Tree.get_nav_bar(
categories,
"",
Expand Down