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

Adding scroll to form if ID is requested in hash #183

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 51 additions & 0 deletions packages/cookie-banner/__tests__/form/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,55 @@ describe(`Cookie banner > DOM > form > render`, () => {
expect(fields[0].checked).toEqual(true);
});

it('Should be scrolled into view', async () => {
document.body.innerHTML = `<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p>
<p>Cookies are a common feature used on almost all websites. A cookie is a small text file that is downloaded onto a device to allow a website to recognise it and to store some information about your preferences.</p>
<p>We use cookies for different reasons, including for managing your shopping cart, measuring your visits on our sites, recognising and remembering your preferences and showing you personalised ads. Learn more about cookies and how we use them.</p><div class="privacy-banner__form-container"></div>`;
cookieBanner({
secure: false,
hideBannerOnFormPage: false,
types: {
test: {
suggested: true,
title: 'Test title',
description: 'Test description',
labels: {
yes: 'Test yes label',
no: 'Test no label'
},
fns: [
() => { }
]
},
performance: {
title: 'Performance preferences',
description: 'Performance cookies are used to measure the performance of our website and make improvements.',
labels: {
yes: 'Pages you visit and actions you take will be measured and used to improve the service',
no: 'Pages you visit and actions you take will not be measured and used to improve the service'
},
fns: [
() => { }
]
}
}
});
const top = document.querySelector(`.${defaults.classNames.form}`).offsetTop

expect(window.scrollY).toEqual(top);
});

sarah-storm marked this conversation as resolved.
Show resolved Hide resolved
});
4 changes: 4 additions & 0 deletions packages/cookie-banner/src/lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ export const initForm = (Store, track = true) => state => {
]
);
});

if(window.location.hash.substring(1) === form.id) {
window.scrollTo(0, form.offsetTop);
sarah-storm marked this conversation as resolved.
Show resolved Hide resolved
}
};

export const renderMessage = button => state => {
Expand Down