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

Enhancement/2734: create visually hidden h2 for section nav component #2743

Merged
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
21 changes: 11 additions & 10 deletions src/components/section-navigation/_macro-options.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
| Name | Type | Required | Description |
| ----------- | ------------- | ------------------------------- | ------------------------------------------------------------------------------------------------------- |
| id | string | false | The HTML `id` of the `<nav>` element of the component |
| classes | string | false | Additional classes for the `<nav>` element |
| ariaLabel | string | false | The `aria-label` attribute for the `<nav>` element to describe its purpose. Defaults to ”Section menu”. |
| variants | string | false | To adjust the orientation of the component using available variant “vertical” |
| currentPath | string | true (unless `tabQuery` set) | Path to the current active page |
| tabQuery | string | true (unless `currentPath` set) | Query parameter in the URL for the current active page |
| title | string | false | The title/header to display in the section navigation element (only for entries without sections) |
| sections | `Array<Item>` | false | An array of [sections](#sections) for the component |
| Name | Type | Required | Description |
| ------------- | ------------- | ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| id | string | false | The HTML `id` of the `<nav>` element of the component |
| classes | string | false | Additional classes for the `<nav>` element |
| hiddenTitle | string | false | The value of the visually hidden `<h2>` element for screen readers. Defaults to "Pages in this section". |
| hiddenTitleId | string | false | The value of the visually hidden title ID. Necessary if you have multiple section navs. Defaults to "section-menu-nav-title". |
| variants | string | false | To adjust the orientation of the component using available variant “vertical” |
| currentPath | string | true (unless `tabQuery` set) | Path to the current active page |
| tabQuery | string | true (unless `currentPath` set) | Query parameter in the URL for the current active page |
| title | string | false | The title/header to display in the section navigation element (only for entries without sections) |
| sections | `Array<Item>` | false | An array of [sections](#sections) for the component |

## Sections

Expand Down
3 changes: 2 additions & 1 deletion src/components/section-navigation/_macro.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{% macro onsSectionNavigation(params) %}
<nav class="ons-section-nav{% if params.variants == 'vertical' %} ons-section-nav--vertical{% endif %} {% if params.classes %} {{ params.classes }} {% endif %}"{% if params.id %} id="{{ params.id }}"{% endif %} aria-label="{{ params.ariaLabel | default("Section menu") }}">
<nav class="ons-section-nav{% if params.variants == 'vertical' %} ons-section-nav--vertical{% endif %} {% if params.classes %} {{ params.classes }} {% endif %}"{% if params.id %} id="{{ params.id }}"{% endif %} aria-labelledby="{{ params.hiddenTitleId | default("section-menu-nav-title")}}">
<h2 class="ons-u-vh" id="{{ params.hiddenTitleId | default("section-menu-nav-title") }}">{{ params.hiddenTitle | default("Pages in this section") }}</h2>
{% if params.sections %}
{% for section in params.sections %}
<div class="ons-section-nav__sub">
Expand Down
15 changes: 2 additions & 13 deletions src/components/section-navigation/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,10 @@ describe('macro: section-navigation', () => {
expect($('.ons-section-nav').hasClass('custom-class')).toBe(true);
});

it('has the provided `ariaLabel` parameter', () => {
const $ = cheerio.load(
renderComponent('section-navigation', {
...EXAMPLE_SECTION_NAVIGATION,
ariaLabel: 'Section navigation menu',
}),
);

expect($('.ons-section-nav').attr('aria-label')).toBe('Section navigation menu');
});

it('assumes a default `ariaLabel` of "Section menu"', () => {
it('assumes a default `hiddenTitleId` of "Section menu"', () => {
const $ = cheerio.load(renderComponent('section-navigation', EXAMPLE_SECTION_NAVIGATION));

expect($('.ons-section-nav').attr('aria-label')).toBe('Section menu');
expect($('.ons-section-nav').attr('aria-labelledby')).toBe('section-menu-nav-title');
});

describe('navigation items', () => {
Expand Down
Loading