Skip to content

Commit

Permalink
Allow the secondary navigation heading to be visually hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Feb 25, 2025
1 parent 0ddad71 commit eddd15a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Added a `<a id="top"></a>` element to the top of the `bodyStart` block to allow for jumping to the top of the page
- Allow the heading of a secondary navigation to be visually hidden with `visuallyHideHeading`

### Changed

Expand Down
24 changes: 24 additions & 0 deletions src/nationalarchives/components/secondary-navigation/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,30 @@
},
"html": "<nav class=\"tna-secondary-navigation\" aria-label=\"Title\"><h2 class=\"tna-secondary-navigation__heading tna-heading-s\">Title</h2><ul class=\"tna-secondary-navigation__items\"><li class=\"tna-secondary-navigation__item\"><a href=\"#/alpha\" class=\"tna-secondary-navigation__link\">Alpha</a></li><li class=\"tna-secondary-navigation__item tna-secondary-navigation__item--current\"><a href=\"#/beta\" class=\"tna-secondary-navigation__link\">Beta</a></li><li class=\"tna-secondary-navigation__item\"><a href=\"#/gamma\" class=\"tna-secondary-navigation__link\">Gamma</a></li></ul></nav>"
},
{
"name": "hidden heading",
"options": {
"title": "Title",
"headingLevel": 2,
"items": [
{
"name": "Alpha",
"href": "#/alpha"
},
{
"name": "Beta",
"href": "#/beta",
"current": true
},
{
"name": "Gamma",
"href": "#/gamma"
}
],
"visuallyHideHeading": true
},
"html": "<nav class=\"tna-secondary-navigation tna-secondary-navigation--unindent\" aria-label=\"Title\"><h2 class=\"tna-secondary-navigation__heading tna-heading-s tna-visually-hidden\">Title</h2><ul class=\"tna-secondary-navigation__items\"><li class=\"tna-secondary-navigation__item\"><a href=\"#/alpha\" class=\"tna-secondary-navigation__link\">Alpha</a></li><li class=\"tna-secondary-navigation__item tna-secondary-navigation__item--current\"><a href=\"#/beta\" class=\"tna-secondary-navigation__link\">Beta</a></li><li class=\"tna-secondary-navigation__item\"><a href=\"#/gamma\" class=\"tna-secondary-navigation__link\">Gamma</a></li></ul></nav>"
},
{
"name": "with classes",
"options": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"required": true,
"description": ""
},
{
"name": "visuallyHideHeading",
"type": "boolean",
"required": false,
"description": "",
"default": false
},
{
"name": "items",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const argTypes = {
noBottomBorder: { control: "boolean" },
overflow: { control: "boolean" },
noUnindentation: { control: "boolean" },
visuallyHideHeading: { control: "boolean" },
classes: { control: "text" },
attributes: { control: "object" },
};
Expand All @@ -31,6 +32,7 @@ const Template = ({
noBottomBorder,
overflow,
noUnindentation,
visuallyHideHeading,
classes,
attributes,
}) =>
Expand All @@ -43,6 +45,7 @@ const Template = ({
noBottomBorder,
overflow,
noUnindentation,
visuallyHideHeading,
classes,
attributes,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{%- endif -%}
{%- set classes = containerClasses | join(' ') -%}
<nav class="tna-secondary-navigation{% if classes %} {{ classes }}{% endif %}" aria-label="{{ params.title }}"{% for attribute, value in params.attributes %} {{ attribute }}{% if value !== '' %}="{{ value }}"{% endif %}{% endfor %}>
<h{{ params.headingLevel }} class="tna-secondary-navigation__heading tna-heading-s">
<h{{ params.headingLevel }} class="tna-secondary-navigation__heading tna-heading-s{% if params.visuallyHideHeading %} tna-visually-hidden{% endif %}">
{{ params.title }}
</h{{ params.headingLevel }}>
<ul class="tna-secondary-navigation__items">
Expand Down
14 changes: 7 additions & 7 deletions src/nationalarchives/components/sidebar/sidebar.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@use "../../variables/a11y";
@use "../../variables/a11y" as a11yVars;
@use "../../tools/borders";
@use "../../tools/colour";
@use "../../tools/media";
Expand All @@ -23,7 +23,7 @@
}

&__items {
padding-top: max(spacing.space(0.5), #{a11y.$focus-outline-padding});
padding-top: max(spacing.space(0.5), #{a11yVars.$focus-outline-padding});

// &:focus {
// outline: none;
Expand Down Expand Up @@ -151,7 +151,7 @@

&--sticky &__items {
margin: 0;
padding-bottom: a11y.$focus-outline-padding;
padding-bottom: a11yVars.$focus-outline-padding;

overflow-y: auto;

Expand All @@ -165,13 +165,13 @@

&--sticky#{&}--sections &__items,
&--sticky#{&}--pages &__items {
width: calc(100% - #{a11y.$focus-outline-padding});
padding-right: a11y.$focus-outline-padding;
padding-left: a11y.$focus-outline-padding;
width: calc(100% - #{a11yVars.$focus-outline-padding});
padding-right: a11yVars.$focus-outline-padding;
padding-left: a11yVars.$focus-outline-padding;

box-sizing: content-box;

position: relative;
left: -#{a11y.$focus-outline-padding};
left: -#{a11yVars.$focus-outline-padding};
}
}

0 comments on commit eddd15a

Please sign in to comment.