From 06743de99833c62ffde2e04cddc8bd846a26e547 Mon Sep 17 00:00:00 2001 From: Colin Rotherham Date: Thu, 20 Jul 2023 01:08:37 +0100 Subject: [PATCH] Remove checks for matchMedia All es6 modules supporting browsers support window.matchMedia https://caniuse.com/matchmedia --- src/javascripts/components/navigation.mjs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/javascripts/components/navigation.mjs b/src/javascripts/components/navigation.mjs index 25b5152723..679786397d 100644 --- a/src/javascripts/components/navigation.mjs +++ b/src/javascripts/components/navigation.mjs @@ -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()