Adrien Denat commited on
Commit
64263c4
1 Parent(s): ca616cc

fix deepestChild function throwing error (#213)

Browse files

* fix deepestChild function throwing error

* let -> const

* remove unecessary var

Files changed (1) hide show
  1. src/lib/utils/deepestChild.ts +4 -5
src/lib/utils/deepestChild.ts CHANGED
@@ -1,7 +1,6 @@
1
- export function deepestChild(el: HTMLElement) {
2
- let newEl = el;
3
- while (newEl.hasChildNodes()) {
4
- newEl = newEl.lastElementChild as HTMLElement;
5
  }
6
- return newEl;
7
  }
 
1
+ export function deepestChild(el: HTMLElement): HTMLElement {
2
+ if (el.lastElementChild && el.lastElementChild.nodeType !== Node.TEXT_NODE) {
3
+ return deepestChild(el.lastElementChild as HTMLElement);
 
4
  }
5
+ return el;
6
  }