Replace DomUtil.empty() with Element.replaceChildren() (#8736)

This commit is contained in:
Jon Koops
2022-12-22 20:23:14 +01:00
committed by GitHub
parent 2f6aad5d48
commit 8314c9e11d
4 changed files with 3 additions and 28 deletions

View File

@ -63,22 +63,6 @@ describe('DomUtil', () => {
});
});
describe('#empty', () => {
it('removes all children of element', () => {
L.DomUtil.create('div', 'test', el);
L.DomUtil.create('div', 'test1', el);
L.DomUtil.create('div', 'test2', el);
L.DomUtil.empty(el);
expect(el.childNodes.length).to.be(0);
});
it('does nothing if element doesn\'t have children', () => {
expect(el.childNodes.length).to.be(0);
L.DomUtil.empty(el);
expect(el.childNodes.length).to.be(0);
});
});
describe('#toFront', () => {
it('moves el to last child position parent element', () => {
const elm = L.DomUtil.create('div', 'childContainer', el);

View File

@ -256,8 +256,8 @@ export const Layers = Control.extend({
_update() {
if (!this._container) { return this; }
DomUtil.empty(this._baseLayersList);
DomUtil.empty(this._overlaysList);
this._baseLayersList.replaceChildren();
this._overlaysList.replaceChildren();
this._layerControlInputs = [];
let baseLayersPresent, overlaysPresent, i, obj, baseLayersCount = 0;

View File

@ -45,14 +45,6 @@ export function create(tagName, className, container) {
return el;
}
// @function empty(el: HTMLElement)
// Removes all of `el`'s children elements from `el`
export function empty(el) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
}
// @function toFront(el: HTMLElement)
// Makes `el` the last child of its parent, so it renders in front of the other children.
export function toFront(el) {

View File

@ -1,6 +1,5 @@
import {Icon} from './Icon';
import {toPoint as point} from '../../geometry/Point';
import {empty} from '../../dom/DomUtil';
/*
* @class DivIcon
@ -47,7 +46,7 @@ export const DivIcon = Icon.extend({
options = this.options;
if (options.html instanceof Element) {
empty(div);
div.replaceChildren();
div.appendChild(options.html);
} else {
div.innerHTML = options.html !== false ? options.html : '';