Skip to content

Commit 0b93a0a

Browse files
author
Brion Fuller
committed
fix: add hidden input for lit-element after render completes
1 parent bad5c24 commit 0b93a0a

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: src/types.ts

+4
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ export interface ICustomElement extends HTMLElement {
6060
disabled?: boolean;
6161
}
6262

63+
export interface ILitElement extends ICustomElement {
64+
updateComplete: Promise<void>;
65+
}
66+
6367
export type LabelsList = NodeListOf<HTMLLabelElement>|[];

Diff for: src/utils.ts

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

44
const observerConfig: MutationObserverInit = { attributes: true };
55

@@ -47,11 +47,15 @@ export const removeHiddenInputs = (internals: IElementInternals): void => {
4747
* @param {IElementInternals} internals - The element internals instance for the ref
4848
* @return {HTMLInputElement} The hidden input
4949
*/
50-
export const createHiddenInput = (ref: ICustomElement, internals: IElementInternals): HTMLInputElement | null => {
50+
export const createHiddenInput = (ref: ICustomElement | ILitElement, internals: IElementInternals): HTMLInputElement | null => {
5151
const input = document.createElement('input');
5252
input.type = 'hidden';
5353
input.name = ref.getAttribute('name');
54-
ref.after(input);
54+
if ((<ILitElement>ref).updateComplete) {
55+
(<ILitElement>ref).updateComplete.then(() => ref.after(input));
56+
} else {
57+
ref.after(input);
58+
}
5559
hiddenInputMap.get(internals).push(input);
5660
return input;
5761
}

0 commit comments

Comments
 (0)