Skip to content

Instantly share code, notes, and snippets.

@mbmohib
Last active November 1, 2018 18:29
Show Gist options
  • Save mbmohib/c5e664f6457c38a0d3d434060275e6a8 to your computer and use it in GitHub Desktop.
Save mbmohib/c5e664f6457c38a0d3d434060275e6a8 to your computer and use it in GitHub Desktop.
Add Arrow to nested Dropdown Menu
/**
* Find any element that has dropdown ul
* and add "down arrow" to 1st level
* and "right arrow" to 2nd level
*
* @param {*} nodeList
*/
const addArrowIconToDropdown = (nodeList) => {
const nodeListArray = Array.prototype.slice.call(nodeList)
nodeListArray.length > 0 && nodeListArray.forEach(list => {
if (list.querySelector('ul')) {
if (list.querySelectorAll('ul').length > 1) {
list.querySelector('a').insertAdjacentHTML('beforeend', '<span uk-icon="triangle-down"></span>')
} else {
list.querySelector('a').insertAdjacentHTML('beforeend', '<span uk-icon="triangle-right"></span>')
}
}
})
}
export default addArrowIconToDropdown;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment