Skip to content

Commit

Permalink
Control cookie message focus on accept or reject
Browse files Browse the repository at this point in the history
  • Loading branch information
ahosgood committed Sep 14, 2023
1 parent b57fa57 commit e8ebf8d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
### Changed

- Focus on the confirmation message of the cookie banner once accepted or rejected

### Deprecated
### Removed
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ export class CookieBanner {
this.$prompt.setAttribute("hidden", true);
this.complete();
this.$acceptedMessage.removeAttribute("hidden");
this.$acceptedMessage.focus();
this.$acceptedMessage.setAttribute("tabindex", "-1");
this.cookies.acceptAllPolicies();
if (this.loadScriptsOnAccept) {
this.loadScriptsOnAccept.split(",").forEach((script) => {
Expand All @@ -70,6 +72,8 @@ export class CookieBanner {
this.$prompt.setAttribute("hidden", true);
this.complete();
this.$rejectedMessage.removeAttribute("hidden");
this.$rejectedMessage.focus();
this.$rejectedMessage.setAttribute("tabindex", "-1");
this.cookies.rejectAllPolicies();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
}

&__message {
&:focus {
outline: none !important;
}

&--prompt {
}

Expand Down
4 changes: 2 additions & 2 deletions src/nationalarchives/components/cookie-banner/template.njk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
}) }}
</div>
</div>
<div class="tna-column tna-column--full tna-cookie-banner__message tna-cookie-banner__message--accepted" hidden>
<div class="tna-column tna-column--full tna-cookie-banner__message tna-cookie-banner__message--accepted" tabindex="0" hidden>
<p>
You have accepted optional cookies. You can change your cookie settings on the <a href="#">Cookies page</a>.
</p>
Expand All @@ -43,7 +43,7 @@
}) }}
</div>
</div>
<div class="tna-column tna-column--full tna-cookie-banner__message tna-cookie-banner__message--rejected" hidden>
<div class="tna-column tna-column--full tna-cookie-banner__message tna-cookie-banner__message--rejected" tabindex="0" hidden>
<p>
You have rejected optional cookies. You can change your cookie settings on the <a href="#">Cookies page</a>.
</p>
Expand Down

0 comments on commit e8ebf8d

Please sign in to comment.