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
- Object.assign
- Element.prototype.classList
- Element.prototype.closest
- window.requestAnimationFrame
- CustomEvent

View file

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