- Taxonomic name: M-CHAPTER-INDEX
- Extension: LONG-FORM-ARTICLE
- Current owner: Framework
- Added on: v5.1.0 (03/11/20)
- Updated on: v5.10.0 (10/08/21)
Chapter index
The purpose of the chapter index component is to assist users when navigating the long-form article content. The chapter index acts as navigation to smoothly shift the user from one chapter to another swiftly and succinctly, without throwing the user out of the page flow or jarring their reading experience. The component has a fixed position at all screen sizes.
Design and usage
Structure
- Max number of nine chapters
- Positioned directly before the introductory text (chapter 0).
- Active state for chapter is set as chapter heading is above half way on the screen.
- Chapter headings labels are ommitted at all but large desktop screens; in this latter instance, the headings are only visible when the chapter is active or the link has hover or focus.
Labels
- Chapter titles must be kept as short and susinct as possible, ideally below 45 characters.
- The title for the first chapter (chapter 0) which is not displayed on the page but within the chapter index should be appropriate for the article such as 'Introduction' or 'Foreword'.
Accessibility and screen readers
- Image/text contrast in-line with pre-existing WCAG guidelines and established Framework components
- Ability to disable animation effects
Non-js requirements and considerations
- If supplied it stacks directly before the article body content allowing the user to jump straight down the anchored chapters.
Placement
- Placed directly before the introductory text (chapter 0)
- JS desktop: Fixed to the left side of the first grid column, anchored centrally within the viewport, with a vertical orientation.
- JS tablet and mobile: Anchored to the top of the screen in a horizontal orientation
Use case and exception scenarios
- Designed exclusively for the long-form article template page
Examples
With Non-JS fallback
Interactive example
Code example
<div class="o-long-form-article">
<!-- Chapter hero and author box -->
<div class="o-long-form-article__chapter-index m-chapter-index" data-module="m-chapter-index" data-module-load="true">
<div class="m-chapter-index__inner">
<ol class="m-chapter-index-nav-list">
<li class="m-chapter-index-nav-list__item"><a class="m-chapter-index-control" href="..."><span class="m-chapter-index-control__label">...</span></a></li>
...
</ol>
</div>
</div>
<div class="o-long-form-article-chapter" id="...">
...
</div>
<div class="o-long-form-article-chapter" id="...">
...
</div>
...
</div>
Without Non-JS fallback
Interactive example
Code example
<div class="o-long-form-article">
<!-- Chapter hero and author box -->
<div class="o-long-form-article__chapter-index" data-module="m-chapter-index" data-module-load="true"></div>
<div class="o-long-form-article-chapter" data-chapter-title="...">
...
</div>
<div class="o-long-form-article-chapter">
...
</div>
...
</div>
Development and test
Notes for developers
Non-JS fallback
It is possible to use the chapter index with and without a non-js fallback. If technology prohibits, generating the non-js fallback simply include the empty placeholder and the JavaScript will build the component on the fly.
Ensure an introductory title is supplied for chapter 0, for example 'Introduction' or 'Foreword', by using the data attribute data-chapter-title
on the first o-long-form-article-chapter
area when no non-js fallback has been supplied.
Controling the chapter index component programatically
Chapter index can be controlled programatically to scroll to a section by index or id. The following method is available for use:
Method | Description |
---|---|
goTo( 5 ) |
Scroll to chapter with given index. The indexes match the numbers shown on the chapter index itself. |
goTo( 'chapterId' ) |
Scroll to the chapter with the given ID. The is must match the one for the applied to the o-long-form-article-chapter element. |
For example:
document.addEventListener( 'frameworkready', function () {
FRAMEWORK.require([ 'blocks/m-chapter-index' ], function ( mChapterIndexModule ) {
var mChapterIndexEl = document.querySelector( '#chapterIndexId' ),
mChapterIndexInstance = mChapterIndexModule.initInstance( mChapterIndexEl ); mChapterIndexInstance.goTo( 5 );
});
});
Changing locale settings
Default next and previous hidden link text can be changed for a particular locale.
en: {
mChapterIndex : {
previousText : 'Previous',
nextText : 'Next',
},
},
For more information on this, see our page on how to change locale settings within JavaScript.
Extension component
This component forms part of the 'long-form-article' extension and so requires an additional stylesheet to be loaded in order to be used; include the following code in the header of your page to attach the relevant additional stylesheet:
<link media="all" href="./assets/[ theme type ]/[ release version ]/[ organisation ]/[ theme name ]/css/long-form-article.css" rel="stylesheet" />
Classes overview
The following table gives you a quick overview of the CSS classes that can be applied.
Class | Outcome | Required | Applied to | Comments |
---|---|---|---|---|
.m-chapter-index |
Container for the chapter index | Yes | .o-long-form-article__chapter-index |
|
.m-chapter-index__inner |
Wrapper for the chapter list | Yes | .m-chapter-index > div |
|
.m-chapter-index-nav-list |
List of chapter links | Yes | .m-chapter-index__inner > ol |
|
.m-chapter-index-nav-list__item |
Chapter list item | Yes | .m-chapter-index-nav-list > li |
|
.m-chapter-index-control |
Chapter link | Yes | .m-chapter-index-nav-list__item > a |
|
.m-chapter-index-control__label |
Chapter link label text | Yes | .m-chapter-index-control > span |
Keyboard operations
- TAB
-
Tabbing to an anchor should make the anchor clearly visually different so that the focus point on the page is obvious to the user.
- SPACE or ENTER
-
With focus on an anchor, pressing SPACE or ENTER will scroll the page to the selected chapter.
Component releases
- Added on: v5.1.0 (03/11/20)
- Updated on: v5.10.0 (10/08/21)
Latest update:
- updated: Chapter index can now be controlled programatically to scroll to a section by index or id.