Skip to content

Commit d819cef

Browse files
fix: remove lit-specific code which is unneeded after a previous fix
1 parent 233f8a8 commit d819cef

File tree

4 files changed

+6
-27
lines changed

4 files changed

+6
-27
lines changed

Diff for: src/element-internals.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import {
1212
createHiddenInput,
1313
findParentForm,
14-
getHostRoot,
1514
initRef,
1615
overrideFormMethod,
1716
removeHiddenInputs,
@@ -127,7 +126,7 @@ export class ElementInternals implements IElementInternals {
127126
const ref = refMap.get(this);
128127
throwIfNotFormAssociated(ref, `Failed to read the 'labels' property from 'ElementInternals': The target element is not a form-associated custom element.`);
129128
const id = ref.getAttribute('id');
130-
const hostRoot = getHostRoot(ref);
129+
const hostRoot = ref.getRootNode() as Element;
131130
if (hostRoot && id) {
132131
return hostRoot ? hostRoot.querySelectorAll(`[for=${id}]`) : [];
133132
}

Diff for: src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ElementInternals } from './element-internals';
2-
import './element-internals';
32
import { CustomStateSet } from './CustomStateSet';
3+
import './element-internals';
44
export * from './types';
55

66
declare global {

Diff for: src/types.ts

-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,4 @@ export interface ICustomElement extends HTMLElement {
7575
disabled?: boolean;
7676
}
7777

78-
export interface ILitElement extends ICustomElement {
79-
updateComplete: Promise<void>;
80-
}
81-
8278
export type LabelsList = NodeListOf<HTMLLabelElement> | [];

Diff for: src/utils.ts

+4-20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { hiddenInputMap, formsMap, formElementsMap, internalsMap, documentFragmentMap } from './maps.js';
2-
import { ICustomElement, IElementInternals, ILitElement, LabelsList } from './types.js';
1+
import { hiddenInputMap, formsMap, formElementsMap, internalsMap } from './maps.js';
2+
import { ICustomElement, IElementInternals, LabelsList } from './types.js';
33

44
const observerConfig: MutationObserverInit = { attributes: true, attributeFilter: ['disabled'] };
55

@@ -15,18 +15,6 @@ const observer = new MutationObserver((mutationsList: MutationRecord[]) => {
1515
}
1616
});
1717

18-
/** Recursively get the host root */
19-
export const getHostRoot = (node: Node): Node&ParentNode => {
20-
if (node instanceof Document) {
21-
return node;
22-
}
23-
let parent = node.parentNode;
24-
if (parent && parent.toString() !== '[object ShadowRoot]') {
25-
parent = getHostRoot(parent);
26-
}
27-
return parent;
28-
};
29-
3018
/**
3119
* Removes all hidden inputs for the given element internals instance
3220
* @param {IElementInternals} internals - The element internals instance
@@ -46,15 +34,11 @@ export const removeHiddenInputs = (internals: IElementInternals): void => {
4634
* @param {IElementInternals} internals - The element internals instance for the ref
4735
* @return {HTMLInputElement} The hidden input
4836
*/
49-
export const createHiddenInput = (ref: ICustomElement | ILitElement, internals: IElementInternals): HTMLInputElement | null => {
37+
export const createHiddenInput = (ref: ICustomElement, internals: IElementInternals): HTMLInputElement | null => {
5038
const input = document.createElement('input');
5139
input.type = 'hidden';
5240
input.name = ref.getAttribute('name');
53-
if ((<ILitElement>ref).updateComplete) {
54-
(<ILitElement>ref).updateComplete.then(() => ref.after(input));
55-
} else {
56-
ref.after(input);
57-
}
41+
ref.after(input);
5842
hiddenInputMap.get(internals).push(input);
5943
return input;
6044
}

0 commit comments

Comments
 (0)