Skip to content

fix(a11y): Add bold font to selected nav items #1894

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

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions .changeset/cuddly-years-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@stackoverflow/stacks": patch
---

Set selected navigation items to bold
18 changes: 18 additions & 0 deletions docs/_data/navigation.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"applies": "Child of <code class=\"stacks-code\">.s-navigation</code>",
"description": "The individual pill-shaped link in a navigation"
},
{
"class": ".s-navigation--item-text",
"applies": "Child of <code class=\"stacks-code\">.s-navigation--item</code>",
"description": "The element meant to contain the text of the navigation item"
},
{
"class": ".is-selected",
"applies": "<code class=\"stacks-code\">.s-navigation--item</code>",
Expand All @@ -40,5 +45,18 @@
"applies": "<code class=\"stacks-code\">.s-navigation--item</code>",
"description": "Adds a small caret that indicates a dropdown"
}
],
"navigation-attributes": [
{
"title": "Preventing layout shift",
"description": "Horizontal layout shift may occur when changing which item is selected within the navigation component. We recommend including the <code class=\"stacks-code\">data-text</code> attribute on the child navigation item text element with the value duplicating the text of the item to prevent the layout shift. See below for examples.",
"attributes": [
{
"attribute": "data-text=\"[value]\"",
"applies": ".s-navigation--item-text",
"description": "Prevents layout shift when changing selected button. Value should be the text of the navigation item."
}
]
}
]
}
8 changes: 6 additions & 2 deletions docs/_includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@

{% if site-navigation %}
<nav aria-label="Global" class="sm:d-none">
<ul class="s-navigation ml8 fw-nowrap sm:d-none">
<ul class="s-navigation ml8 fw-nowrap">
{% assign slug = page.url | replace:'/',' ' | truncatewords: 2 | remove:'...' %}

{% for section in site-navigation.sections %}
{% assign url = section.url | replace:'/',' ' | truncatewords: 2 | remove:'...' %}
<li><a class="s-navigation--item{% if url == slug %} is-selected{% endif %}" href="{{ section.url }}" {% if url == slug %} aria-current="page"{% endif %}>{{ section.title }}</a></li>
<li>
<a class="s-navigation--item{% if url == slug %} is-selected{% endif %}" href="{{ section.url }}" {% if url == slug %} aria-current="page"{% endif %}>
<span class="s-navigation--item-text" data-text="{{ section.title }}">{{ section.title }}</span>
</a>
</li>
{% endfor %}
</ul>
</nav>
Expand Down
18 changes: 11 additions & 7 deletions docs/_includes/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
<div class="d-none sm:d-block">
<div class="d-flex fd-column ai-center">
{% if site-navigation %}
<nav class="s-navigation s-navigation__wrap mx8 mb12 jc-center" aria-label="Global">
{% assign slug = page.url | replace:'/',' ' | truncatewords: 2 | remove:'...' %}
<nav aria-label="Global" class="sm:d-none">
<ul class="s-navigation s-navigation__wrap mx8 mb12 jc-center">
{% assign slug = page.url | replace:'/',' ' | truncatewords: 2 | remove:'...' %}

{% for section in site-navigation.sections %}
{% assign url = section.url | replace:'/',' ' | truncatewords: 2 | remove:'...' %}
<a class="s-navigation--item{% if url == slug %} is-selected{% endif %}" href="{{ section.url }}">{{ section.title }}</a>
{% endfor %}
{% for section in site-navigation.sections %}
{% assign url = section.url | replace:'/',' ' | truncatewords: 2 | remove:'...' %}
<a class="s-navigation--item{% if url == slug %} is-selected{% endif %}" href="{{ section.url }}">
<span class="s-navigation--item-text" data-text="{{ section.title }}">{{ section.title }}</span>
</a>
{% endfor %}
</ul>
</nav>
{% endif %}
</div>
Expand All @@ -30,7 +34,7 @@
{% if section.links %}
{% for link in section.links %}
<a class="s-navigation--item {% if page.url == link.url %}is-selected{% endif %}" href="{{ link.url | url }}" {% if page.url == link.url %}aria-current="page"{% endif %}>
{{ link.title }}
<span class="s-navigation--item-text" data-text="{{ link.title }}">{{ link.title }}</span>
</a>
{% endfor %}
{% endif %}
Expand Down
8 changes: 4 additions & 4 deletions docs/_includes/topbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@
{% if showFullNavigation %}
<li>
<a href="#" class="s-navigation--item">
About
<span class="s-navigation--item-text" data-text="About">About</span>
</a>
</li>
<li>
<a href="#" class="s-navigation--item is-selected">
Products
<span class="s-navigation--item-text" data-text="Products">Products</span>
</a>
</li>
<li>
<a href="#" class="s-navigation--item">
For Teams
<span class="s-navigation--item-text" data-text="For Teams">For Teams</span>
</a>
</li>
{% else %}
<li>
<a href="#" class="s-navigation--item">
Products
<span class="s-navigation--item-text" data-text="Products">Products</span>
</a>
</li>
{% endif %}
Expand Down
Loading