Skip to content

Commit

Permalink
Update option-select.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-kirwan committed Aug 22, 2023
1 parent bad03ea commit 193e2a4
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions app/assets/javascripts/components/option-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
var button = this.$optionSelect.querySelector('.js-container-button')
button.addEventListener('click', this.toggleOptionSelect.bind(this))

// Toggle option visibility depending on screen size (min-width: 641px)
// and presence of closed options (this.isClosedOnLoadMobile, this.isClosedOnLoad)
// Toggle option visibility depending on screen size (min-width: 641px) and
// presence of any 'closed' properties (`data-closed-on-load`, `data-closed-on-load-mobile`)
if (this.mq.matches) {
this.toggleOptionVisibility(this.isClosedOnLoad === 'true')
this.toggleVisibility(true)
} else {
this.toggleOptionVisibility(this.hasAnyClosedOptions())
this.toggleVisibility(false)
}

var checkedString = this.checkedString()
Expand All @@ -75,18 +75,22 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
}
}

OptionSelect.prototype.toggleOptionVisibility = function (hasClosedProperty) {
if (hasClosedProperty) {
this.close()
OptionSelect.prototype.toggleVisibility = function (isDesktop) {
if (isDesktop) {
if (this.isClosedOnLoad === 'true') {
this.close()
} else {
this.setupHeight()
}
} else {
this.setupHeight()
if (this.isClosedOnLoadMobile === 'true' || this.isClosedOnLoad === 'true') {
this.close()
} else {
this.setContainerHeight(201)
}
}
}

OptionSelect.prototype.hasAnyClosedOptions = function () {
return this.isClosedOnLoadMobile === 'true' || this.isClosedOnLoad === 'true'
}

OptionSelect.prototype.typeFilterText = function (event) {
event.stopPropagation()
var ENTER_KEY = 13
Expand Down Expand Up @@ -277,7 +281,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};
}

OptionSelect.prototype.setupHeight = function setupHeight () {
// get height of option container
// get height of option container e.g.
var initialOptionContainerHeight = this.$optionsContainer.clientHeight
// get height of option container ul (containg items)
var height = this.$optionList.offsetHeight
Expand Down

0 comments on commit 193e2a4

Please sign in to comment.