Skip to content

Commit

Permalink
Remove checks for matchMedia
Browse files Browse the repository at this point in the history
All es6 modules supporting browsers support window.matchMedia
https://caniuse.com/matchmedia
  • Loading branch information
colinrotherham committed Jul 26, 2023
1 parent 686bc42 commit e5f45f6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/javascripts/components/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,16 @@ class Navigation {
}

init () {
if ('matchMedia' in window) {
// Set the matchMedia to the govuk-frontend tablet breakpoint
this.mql = window.matchMedia('(min-width: 40.0625em)')

if ('addEventListener' in this.mql) {
this.mql.addEventListener('change', () => this.setHiddenStates())
} else {
// addListener is a deprecated function, however addEventListener
// isn't supported by Safari < 14. We therefore add this in as
// a fallback for those browsers
this.mql.addListener(() => this.setHiddenStates())
}
// Set the matchMedia to the govuk-frontend tablet breakpoint
this.mql = window.matchMedia('(min-width: 40.0625em)')

// MediaQueryList.addEventListener isn't supported by Safari < 14 so we need
// to be able to fall back to the deprecated MediaQueryList.addListener
if ('addEventListener' in this.mql) {
this.mql.addEventListener('change', () => this.setHiddenStates())
} else {
// @ts-expect-error Property 'addListener' does not exist
this.mql.addListener(() => this.setHiddenStates())
}

this.setHiddenStates()
Expand Down

0 comments on commit e5f45f6

Please sign in to comment.