Alpha

This is an alpha release of our documentation site. View the roadmap.

On this page

Examples

With columns

By default the on this page component will display using a column based layout collapsing to a single column on small screens.

<div class="cads-on-this-page cads-on-this-page--columns" data-testid="on-this-page">
  <h2 class="cads-on-this-page__title">On this page</h2>
  <ul class="cads-on-this-page__list">
    <li class="cads-on-this-page__list-item">
      <a href="#link-1"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 1
      </a>
    </li>
    <li class="cads-on-this-page__list-item">
      <a href="#link-2"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 2
      </a>
    </li>
    <li class="cads-on-this-page__list-item">
      <a href="#link-3"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 3
      </a>
    </li>
    <li class="cads-on-this-page__list-item">
      <a href="#link-4"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 4
      </a>
    </li>
  </ul>
</div>
<%= render CitizensAdviceComponents::OnThisPage.new do |c|
  c.with_links([
    { label: "Link 1", id: "link-1" },
    { label: "Link 2", id: "link-2" },
    { label: "Link 3", id: "link-3" },
    { label: "Link 4", id: "link-4" }
  ])
end %>

With no columns

If there are fewer than four link then the component will always display in a single column.

<div class="cads-on-this-page" data-testid="on-this-page">
  <h2 class="cads-on-this-page__title">On this page</h2>
  <ul class="cads-on-this-page__list">
    <li class="cads-on-this-page__list-item">
      <a href="#link-1"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 1
      </a>
    </li>
    <li class="cads-on-this-page__list-item">
      <a href="#link-2"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 2
      </a>
    </li>
    <li class="cads-on-this-page__list-item">
      <a href="#link-3"
          class="cads-on-this-page__link cads-hyperlink"
          data-testid="on-this-page-link">
        Link 3
      </a>
    </li>
  </ul>
</div>
<%= render CitizensAdviceComponents::OnThisPage.new do |c|
  c.with_links([
    { label: "Link 1", id: "link-1" },
    { label: "Link 2", id: "link-2" },
    { label: "Link 3", id: "link-3" }
  ])
end %>

The component supports a variant with nested links. In this configuration the component is always displayed in a single column with the option to expand nested links.

JavaScript behaviour

On this page requires some additional JavaScript behaviour which can be initialised with:

import { initOnThisPage } from '@citizensadvice/design-system';
initOnThisPage();

The JavaScript behaviour is only required if you are using the version of the component with nested links. If you are not using this you don’t need to include this code.

Using with Rails

If you are using the citizens_advice_components gem, you can call the component from within a template using:

Component arguments

Argument Description
Argument show_nested_links Description Optional, will display nested links if there are any. Defaults to false

The on this page component accepts a required links slot. Links are an array of the following options:

Argument Description
Argument id Description Required, used for linking content on the page, and for accessibility purposes
Argument label Description Required, the label of the link
Argument children Description Optional, array for nested links