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

Grid sticky functionality fixed in full pages #2960

Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
793533f
Fix issue and add test
adi-unni Nov 20, 2023
a2b1a98
Update VR images
adi-unni Nov 21, 2023
c470473
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
adi-unni Nov 23, 2023
7563cef
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
adi-unni Dec 1, 2023
42d4bf8
Update reference images
adi-unni Dec 1, 2023
9e40abe
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
alessioventuriniAND Dec 4, 2023
46d5435
Add test skeleton
adi-unni Dec 7, 2023
51e6edb
Add imports
adi-unni Dec 7, 2023
c996a86
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
alessioventuriniAND Dec 7, 2023
6025f83
tried different approach to test
alessioventuriniAND Dec 8, 2023
2ac815a
Update Tests
adi-unni Dec 8, 2023
30ad545
Remove mistaken title
adi-unni Dec 8, 2023
ed1e311
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
alessioventuriniAND Dec 8, 2023
47c74bc
Fix errors
adi-unni Dec 11, 2023
4c8b462
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
adi-unni Dec 11, 2023
97e7e9d
Update VR test
adi-unni Dec 11, 2023
9d9a108
Update test names
adi-unni Dec 11, 2023
3379372
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
alessioventuriniAND Dec 11, 2023
524d10e
Merge branch 'main' into 2835/bug/ons-grid__col-sticky-css-functional…
alessioventuriniAND Dec 12, 2023
1165f39
updated vr and merged main in
alessioventuriniAND Dec 12, 2023
af7b3d4
updated references vr
alessioventuriniAND Dec 13, 2023
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
title: "Example: Table of contents on full page"
layout: ~
---
{% from "components/table-of-contents/_macro.njk" import onsTableOfContents %}

{% extends "layout/_template.njk" %}

{% set pageConfig = {
"header": {
"title": "What is the census?"
rmccar marked this conversation as resolved.
Show resolved Hide resolved
},
"breadcrumbs": {
"ariaLabel": 'Back',
"itemsList": [
{
"url": '/',
"id": "back-example-feedback-form-error",
"text": 'Back',
"attributes": {
"data-attribute": "Example attribute"
}
}
]
},
"footer": {
"OGLLink": {
"pre": 'All content is available under the',
"link": 'Open Government Licence v3.0',
"url": 'https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/',
"post": ', except where otherwise stated'
}
}
} %}

{% block main %}
<div class="ons-page__container ons-container">
<div class="ons-grid ons-js-toc-container">
<div class="ons-grid__col ons-grid__col--sticky@m ons-col-4@m">
{{
onsTableOfContents({
"title": 'Contents',
"ariaLabel": 'Sections in this page',
"itemsList": [
{
"url": '#section1',
"text": 'What is the census?'
},
{
"url": '#section2',
"text": 'The online census has now closed'
},
{
"url": '#section3',
"text": 'What happens after Census Day'
},
{
"url": '#section4',
"text": 'The census in Northern Ireland and Scotland'
},
{
"url": '#section5',
"text": 'The last census'
}
]
})
}}
</div>
<div class="ons-grid__col ons-col-7@m ons-push-1@m">
<section id="section1">
<h2>What is the census?</h2>
<p>The census is a survey that happens every 10 years and gives us a picture of all the people and households in England and Wales.</p>

<p>Your answers to the census questions will help organisations make decisions on planning and funding public services in your area, including transport, education and healthcare.</p>
</section>
<section id="section2">
<h2>The online census has now closed</h2>
<p>Census Day was on Sunday 21 March 2021.</p>

<p>If you still have a paper census questionnaire, fill it in as soon as you can and return it to FREEPOST, Census 2021.</p>
</section>
<section id="section3">
<h2>What happens after Census Day</h2>
<p>Two follow-up surveys, the <a href="#0">Census Coverage Survey</a> and the <a href="#0">Census Quality Survey</a>, help to improve the quality and accuracy of the census results.</p>

<p>Over the next year, we work hard to process the answers from all the census questionnaires. This is so that we can publish the initial Census 2021 findings one year after the census and the main releases two years after the census.</p>

<p>To make sure the Census 2021 statistics we publish meet the needs of those who use them, we also run an outputs consultation.</p>
</section>
<section id="section4">
<h2>The census in Northern Ireland and Scotland</h2>
<p>The Office for National Statistics (ONS) runs the census in England and Wales.</p>

<p>If you live in Northern Ireland, visit the Northern Ireland Statistics Agency (NISRA) census website to find out about the census for Northern Ireland.</p>

<p>If you live in Scotland, visit the National Records of Scotland census website to find out how to take part in the census for Scotland.</p>
</section>
<section id="section5">
<h2>The last census</h2>
<p>The last census took place in 2011. Many people and organisations used information from the 2011 Census in a variety of ways.</p>

<p>For example, Bristol City Council used it to inform decisions on how to fund local housing improvements. It was also essential for the charity Redbridge Council for Voluntary Services to help people from ethnic minority groups learn more about dementia.</p>

<p>To read more about the benefits that information from the 2011 Census helped to create, visit the Office for National Statistics (ONS) website.</p>
<p>The Census Coverage Survey (CCS) was a short, separate survey that we at the Office for National Statistics (ONS) started six to eight weeks after Census Day.</p>

<p>The CCS helps make sure everyone is counted and our census results are as accurate as possible. It asked similar questions to the main census, just fewer of them, at addresses in a selection of postcodes across England and Wales.</p>

<p>The CCS has now closed.</p>
</section>
</div>
</div>
</div>
{% endblock %}
116 changes: 113 additions & 3 deletions src/components/table-of-contents/toc.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
import { renderBaseTemplate, renderComponent, setTestPage } from '../../tests/helpers/rendering';

describe('script: table-of-contents', () => {
beforeEach(async () => {
Expand Down Expand Up @@ -52,10 +52,120 @@ describe('script: table-of-contents', () => {
['section2', 'Second section'],
['section3', 'Third section'],
])('marks "%s" as the current section', async (sectionId, sectionTitle) => {
await page.$eval(`#${sectionId}`, node => node.scrollIntoView());
await page.$eval(`#${sectionId}`, (node) => node.scrollIntoView());
await page.waitForTimeout(250);

const activeSection = await page.$eval('.ons-toc__link-active', node => node.innerText.trim());
const activeSection = await page.$eval('.ons-toc__link-active', (node) => node.innerText.trim());
expect(activeSection).toBe(sectionTitle);
});
});

describe('script: table-of-contents-fixed-position', () => {
beforeEach(async () => {
await setTestPage(
'/test',
`
<div class="ons-page__container ons-container">
<div class="ons-grid ons-js-toc-container">
<div id="sticky-container" class="ons-grid__col ons-grid__col--sticky@m ons-col-4@m">
${renderComponent('table-of-contents', {
title: 'Contents',
ariaLabel: 'Sections in this page',
itemsList: [
{
url: '#section1',
text: 'What is the census?',
},
{
url: '#section2',
text: 'The online census has now closed',
},
{
url: '#section3',
text: 'What happens after Census Day',
},
{
url: '#section4',
text: 'The census in Northern Ireland and Scotland',
},
{
url: '#section5',
text: 'The last census',
},
],
})}
</div>
<div class="ons-grid__col ons-col-7@m ons-push-1@m">
<section id="section1">
<h2>What is the census?</h2>
<p>The census is a survey that happens every 10 years and gives us a picture of all the people and households in England and Wales.</p>

<p>Your answers to the census questions will help organisations make decisions on planning and funding public services in your area, including transport, education and healthcare.</p>
</section>
<section id="section2">
<h2>The online census has now closed</h2>
<p>Census Day was on Sunday 21 March 2021.</p>

<p>If you still have a paper census questionnaire, fill it in as soon as you can and return it to FREEPOST, Census 2021.</p>
</section>
<section id="section3">
<h2>What happens after Census Day</h2>
<p>Two follow-up surveys, the <a href="#0">Census Coverage Survey</a> and the <a href="#0">Census Quality Survey</a>, help to improve the quality and accuracy of the census results.</p>

<p>Over the next year, we work hard to process the answers from all the census questionnaires. This is so that we can publish the initial Census 2021 findings one year after the census and the main releases two years after the census.</p>

<p>To make sure the Census 2021 statistics we publish meet the needs of those who use them, we also run an outputs consultation.</p>
</section>
<section id="section4">
<h2>The census in Northern Ireland and Scotland</h2>
<p>The Office for National Statistics (ONS) runs the census in England and Wales.</p>

<p>If you live in Northern Ireland, visit the Northern Ireland Statistics Agency (NISRA) census website to find out about the census for Northern Ireland.</p>

<p>If you live in Scotland, visit the National Records of Scotland census website to find out how to take part in the census for Scotland.</p>
</section>
<section id="section5">
<h2>The last census</h2>
<p>The last census took place in 2011. Many people and organisations used information from the 2011 Census in a variety of ways.</p>

<p>For example, Bristol City Council used it to inform decisions on how to fund local housing improvements. It was also essential for the charity Redbridge Council for Voluntary Services to help people from ethnic minority groups learn more about dementia.</p>

<p>To read more about the benefits that information from the 2011 Census helped to create, visit the Office for National Statistics (ONS) website.</p>
<p>The Census Coverage Survey (CCS) was a short, separate survey that we at the Office for National Statistics (ONS) started six to eight weeks after Census Day.</p>

<p>The CCS helps make sure everyone is counted and our census results are as accurate as possible. It asked similar questions to the main census, just fewer of them, at addresses in a selection of postcodes across England and Wales.</p>

<p>The CCS has now closed.</p>
</section>
</div>
</div>
</div>
`,
'main',
);
});

it('when the "ons-grid__col--sticky" class is used, then the ToC stays in a fixed position while scrolling', async () => {
await page.evaluate(() => {
window.scrollTo(0, 1000);
});

await page.waitForTimeout(250);
const leftColumn = await page.$('#sticky-container');
const boundingBox = await leftColumn.boundingBox();

const viewport = await page.evaluate(() => ({
width: window.innerWidth,
height: window.innerHeight,
}));

const isInViewport =
boundingBox &&
boundingBox.x < viewport.width &&
boundingBox.y < viewport.height &&
boundingBox.x + boundingBox.width > 0 &&
boundingBox.y + boundingBox.height > 0;

expect(isInViewport).toBeTruthy();
});
});
2 changes: 1 addition & 1 deletion src/scss/objects/_page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
display: flex;
flex-direction: column;
min-height: 100%;
overflow-x: hidden;
overflow-x: clip;
width: 100%;
}

Expand Down
4 changes: 2 additions & 2 deletions src/tests/helpers/rendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ export async function gotoTestPath(path) {
return await page.goto(`http://localhost:${process.env.TEST_PORT}${path}`);
}

export async function setTestPage(path, template) {
export async function setTestPage(path, template, blockName = 'body') {
const response = await gotoTestPath(path);

verifyConsoleSubscription(page);

const compositedTemplate = `
{% block body %}
{% block ${blockName} %}
${template}
{% endblock %}
`;
Expand Down
Loading