Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ csSelector.addEventListener('keyup', function(e) {
})

document.addEventListener('click', function(e) {
if (!e.target.closest('#myCustomSelect')) {
if (!aParentElementHasId(e, 'myCustomSelect', 20)) {
// click outside of the custom group
toggleList('Shut')
setState('initial')
Expand All @@ -93,6 +93,23 @@ document.addEventListener('click', function(e) {
// FUNCTIONS
// /////////////////////////////////

function aParentElementHasId(event, id, maxDepth) {
let currentElement = event.srcElement
let count = 0

while (currentElement !== undefined && currentElement !== null) {
count++
if (currentElement.id === id) {
return true
}
if (maxDepth && count > maxDepth) {
return false
}
currentElement = currentElement.parentElement
}
return false
}

function toggleList(whichWay) {
if (whichWay === 'Open') {
csList.classList.remove('hidden-all')
Expand All @@ -104,8 +121,7 @@ function toggleList(whichWay) {
}

function findFocus() {
const focusPoint = document.activeElement
return focusPoint
return document.activeElement
}

function moveFocus(fromHere, toThere) {
Expand Down Expand Up @@ -188,20 +204,7 @@ function makeChoice(whichOption) {
}

function setState(newState) {
switch (newState) {
case 'initial':
csState = 'initial'
break
case 'opened':
csState = 'opened'
break
case 'filtered':
csState = 'filtered'
break
case 'closed':
csState = 'closed'
}
// console.log({csState})
csState = newState
}

function doKeyAction(whichKey) {
Expand Down