don't reimplement native closest (#696)

This commit is contained in:
Konstantin Vyatkin 2019-10-28 16:26:19 -04:00 committed by Josh Johnson
parent 50fae125ed
commit a2485392a5
2 changed files with 6 additions and 13 deletions

View file

@ -1053,6 +1053,7 @@ Choices is compiled using [Babel](https://babeljs.io/) to enable support for [ES
- Array.prototype.indexOf - Array.prototype.indexOf
- Object.assign - Object.assign
- Element.prototype.classList - Element.prototype.classList
- Element.prototype.closest
- window.requestAnimationFrame - window.requestAnimationFrame
- CustomEvent - CustomEvent

View file

@ -39,19 +39,11 @@ export const wrap = (element, wrapper = document.createElement('div')) => {
return wrapper.appendChild(element); return wrapper.appendChild(element);
}; };
export const findAncestorByAttrName = (el, attr) => { /**
let target = el; * @param {HTMLElement} el
* @param {string} attr
while (target) { */
if (target.hasAttribute(attr)) { export const findAncestorByAttrName = (el, attr) => el.closest(`[${attr}]`);
return target;
}
target = target.parentElement;
}
return null;
};
export const getAdjacentEl = (startEl, className, direction = 1) => { export const getAdjacentEl = (startEl, className, direction = 1) => {
if (!startEl || !className) { if (!startEl || !className) {