Skip to content

Commit

Permalink
Throw errors when CSS custom properties are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrotherham committed Dec 13, 2023
1 parent 53c78f2 commit c5e8c16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/govuk-frontend/src/govuk/components/header/header.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,18 @@ export class Header extends GOVUKFrontendComponent {
* @private
*/
setupResponsiveChecks() {
const breakpointProperty = '--govuk-frontend-breakpoint-desktop'
const breakpointValue = getComputedStyle(document.body).getPropertyValue(
'--govuk-frontend-breakpoint-desktop'
breakpointProperty
)

if (!breakpointValue) {
throw new ElementError({
componentName: 'Header',
identifier: `CSS custom property (\`${breakpointProperty}\`)`
})
}

// Media query list for GOV.UK Frontend desktop breakpoint
this.mql = window.matchMedia(`(min-width: ${breakpointValue})`)

Expand Down
10 changes: 9 additions & 1 deletion packages/govuk-frontend/src/govuk/components/tabs/tabs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,18 @@ export class Tabs extends GOVUKFrontendComponent {
* @private
*/
setupResponsiveChecks() {
const breakpointProperty = '--govuk-frontend-breakpoint-tablet'
const breakpointValue = getComputedStyle(document.body).getPropertyValue(
'--govuk-frontend-breakpoint-tablet'
breakpointProperty
)

if (!breakpointValue) {
throw new ElementError({
componentName: 'Tabs',
identifier: `CSS custom property (\`${breakpointProperty}\`)`
})
}

// Media query list for GOV.UK Frontend tablet breakpoint
this.mql = window.matchMedia(`(min-width: ${breakpointValue})`)

Expand Down

0 comments on commit c5e8c16

Please sign in to comment.