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

Can we display the banner by default without javascript? #125

Open
andybroomfield opened this issue Apr 29, 2021 · 4 comments
Open

Can we display the banner by default without javascript? #125

andybroomfield opened this issue Apr 29, 2021 · 4 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@andybroomfield
Copy link
Contributor

Currently the banner requires javascript to display.
This is so that if a user has hidden the banner, there isn't a flash of the banner appearing breifly, as the logic to hide the banner is in javascript.
Is it possible to reverse this and have it so the banner is displayed by default and hidden server side?
I think the problem before was when the internal page caching module was turned on.

@andybroomfield andybroomfield added the enhancement New feature or request label Apr 29, 2021
@andybroomfield andybroomfield added the question Further information is requested label May 11, 2021
@finnlewis
Copy link
Member

@markconroy mentioned putting the block in tag with display block. This would then render it Javascript is disabled.

@markconroy
Copy link
Member

markconroy commented May 11, 2021

@finnlewis @andybroomfield Yes, we had a similar issue recently and our solution was like this:

  1. use display: none; on the alert to avoid the flash of seeing it before it's hidden
  2. use JS to then show the banner, but in case JS is not loading then
  3. Add
  <noscript>
    <style>
      .localgov-alert-banner {display: block;}
    </style>
  </noscript>

in the template.

@danchamp
Copy link
Collaborator

Is it possible to reverse this and have it so the banner is displayed by default and hidden server side?

+1 for hiding banners server side since it would also remove the dependency on CSS to hide the banner.

At the moment a hidden banner is still present in the HTML on subsequent page loads, and will be shown / announced to users if CSS is not available for any reason, or run the risk of a FOUC.

At the least we should add aria-hidden to hidden banners, but it feels cleaner to check for the presence of a cookie for the banner server-side, and not render it at all if it's been hidden.

@markconroy
Copy link
Member

Within the new theme we have a .no-js class that is present on initial load but removed straighaway by JS.

We could use something like .no-js .localgov-alert-banner { display: block; }.

I like @danchamp idea of doing this server side if possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants