Skip to content

Commit

Permalink
Add button to queryselector and a fallback if button element is not p…
Browse files Browse the repository at this point in the history
…resent (#413)
  • Loading branch information
laurenhitchon authored Jun 12, 2024
1 parent 4e3933e commit b833b55
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/components/header/header.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
class SiteSearch {
constructor(element) {
this.triggerButton = element
this.element = element
this.originalButton = document.querySelector('.js-open-search')
this.targetElement = document.getElementById(this.triggerButton.getAttribute('aria-controls'))
this.searchInput = this.targetElement.querySelector('.js-search-input')
this.pressed = this.triggerButton.getAttribute('aria-expanded') === 'true'
this.targetElement = document.getElementById(this.element.getAttribute('aria-controls'))
this.searchInput = this.targetElement.querySelector('input.js-search-input')
this.pressed = this.element.getAttribute('aria-expanded') === 'true'
}

init() {
if (!this.originalButton) return
this.controls()
}

controls() {
this.triggerButton.addEventListener('click', this.showHide.bind(this), false)
this.element.addEventListener('click', this.showHide.bind(this), false)
}

showHide() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function initSite() {
const accordions = document.querySelectorAll('.js-accordion')
const backTop = document.querySelectorAll('button.js-back-to-top')
const carousel = document.querySelectorAll('.js-carousel')
const closeSearchButton = document.querySelectorAll('.js-close-search')
const closeSearchButton = document.querySelectorAll('button.js-close-search')
const datePicker = document.querySelectorAll('.js-date-input')
const dialogs = document.querySelectorAll('.js-dialog')
const fileUpload = document.querySelectorAll('.js-file-upload')
Expand All @@ -50,7 +50,7 @@ function initSite() {
const link = document.querySelectorAll('a.js-link')
const multiSelect = document.querySelectorAll('.js-multi-select')
const navigation = document.getElementById('main-nav')
const openSearchButton = document.querySelectorAll('.js-open-search')
const openSearchButton = document.querySelectorAll('button.js-open-search')
const popover = document.querySelectorAll('.js-popover')
const tabs = document.querySelectorAll('.js-tabs')
const toggletip = document.querySelectorAll('.js-toggletip')
Expand Down

0 comments on commit b833b55

Please sign in to comment.