-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure IDs on collapsible navigation are unique
Multiple nested pages were getting assigned the same ID (from the parent). This change appends the iterator index to the elements to make sure they're unique. Also added a extra nested page to the example docs and a test.
- Loading branch information
Jakub Miarka
committed
Nov 15, 2019
1 parent
0d85600
commit c186288
Showing
4 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
example/source/nested-page/another-nested-nested-page/index.html.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
title: Another nested nested page | ||
--- | ||
|
||
# Another nested nested page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
describe('Collapsible navigation', function () { | ||
'use strict' | ||
|
||
var module | ||
var $navigation | ||
|
||
beforeEach(function () { | ||
module = new GOVUK.Modules.CollapsibleNavigation() | ||
$navigation = $(` | ||
<nav id="toc" class="js-toc-list toc__list" aria-labelledby="toc-heading" data-module="collapsible-navigation"> | ||
<ul> | ||
<li> | ||
<a href="/nested-page/"><span>Nested page</span></a> | ||
<ul> | ||
<li> | ||
<a href="/nested-page/another-nested-page/#another-nested-page"><span>Another nested page</span></a> | ||
</li> | ||
</ul> | ||
<ul> | ||
<li> | ||
<a href="/nested-page/another-nested-nested-page/#another-nested-nested-page"><span>Another nested nested page</span></a> | ||
</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</nav>`) | ||
module.start($navigation) | ||
}) | ||
|
||
it('sanitizes headings to unique IDs correctly', function () { | ||
$navigation.find('ul > li > ul').each(function (i) { | ||
expect($(this)[0].id).toEqual('toc-nested-page-' + i) | ||
}) | ||
}) | ||
}) |