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

Remove hardcoded media query breakpoints from the JavaScript for the header and tabs components #3764

Closed
2 tasks done
36degrees opened this issue Jun 7, 2023 · 0 comments · Fixed by #4562
Closed
2 tasks done

Comments

@36degrees
Copy link
Contributor

36degrees commented Jun 7, 2023

What

We have hardcoded the default desktop and tablet breakpoints into the JavaScript for both the header and tabs components:

// Set the matchMedia to the govuk-frontend desktop breakpoint
this.mql = window.matchMedia('(min-width: 48.0625em)')

/** @deprecated Will be made private in v5.0 */
this.mql = window.matchMedia('(min-width: 40.0625em)')

Find another way to link the JavaScript behaviour to the styles applied at different breakpoints without needing to hardcode them.

Why

Having the breakpoints hardcoded is likely cause issues if users override the default breakpoints.

There's also a risk that they may get out of sync if we ever make changes to the default breakpoints.

Further details

Once we've switched to loading our JavaScript using script type="module"1 we might be able to expose the breakpoint as a CSS variable in the CSS for each component (or on the document root) and read it out using window.getComputedStyle().getPropertyValue.

Who needs to work on this

Developers

Who needs to review this

Developers

Done when

  • Hardcoded desktop breakpoint removed from the JavaScript for the header component
  • Hardcoded tablet breakpoint removed from the JavaScript for the header component

Footnotes

  1. because all browsers that support script type="module" also support CSS variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants