Skip to content

Commit ebbb8ef

Browse files
brion-fullerBrion Fuller
and
Brion Fuller
authored
fix: add hidden input for lit-element after render completes (#27)
* fix: add hidden input for lit-element after render completes * chore(release): 0.1.10 * chore(release): 0.1.11 * chore(release): 0.1.12 * chore(release): 0.1.13 * Add null type to setFormValue * chore(release): 0.1.14 Co-authored-by: Brion Fuller <[email protected]>
1 parent bad5c24 commit ebbb8ef

File tree

6 files changed

+46
-12
lines changed

6 files changed

+46
-12
lines changed

Diff for: CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
### [0.1.14](https://github.com/calebdwilliams/element-internals-polyfill/compare/v0.1.13...v0.1.14) (2021-03-08)
6+
7+
### [0.1.13](https://github.com/calebdwilliams/element-internals-polyfill/compare/v0.1.12...v0.1.13) (2021-03-08)
8+
9+
### [0.1.12](https://github.com/calebdwilliams/element-internals-polyfill/compare/v0.1.11...v0.1.12) (2021-03-08)
10+
11+
### [0.1.11](https://github.com/calebdwilliams/element-internals-polyfill/compare/v0.1.10...v0.1.11) (2021-03-08)
12+
13+
### [0.1.10](https://github.com/calebdwilliams/element-internals-polyfill/compare/v0.1.9...v0.1.10) (2021-03-08)
14+
15+
16+
### Bug Fixes
17+
18+
* add hidden input for lit-element after render completes ([0b93a0a](https://github.com/calebdwilliams/element-internals-polyfill/commit/0b93a0a94158ca83caa82a1b9bd1a3381ca7b322))
19+
520
### [0.1.9](https://github.com/calebdwilliams/element-internals-polyfill/compare/v0.1.8...v0.1.9) (2021-02-23)
621

722

Diff for: package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "element-internals-polyfill",
3-
"version": "0.1.9",
2+
"name": "@simplex/element-internals-polyfill",
3+
"version": "0.1.14",
44
"description": "A polyfill for the element internals specification",
55
"main": "dist/index.js",
66
"module": "dist/index.js",
@@ -19,6 +19,9 @@
1919
"release": "standard-version",
2020
"postrelease": "git push --follow-tags origin master; npm publish"
2121
},
22+
"publishConfig": {
23+
"registry": "https://pkgs.dev.azure.com/daimler-mic/_packaging/mercedes-developer-experience/npm/registry/"
24+
},
2225
"repository": {
2326
"type": "git",
2427
"url": "git+https://github.com/calebdwilliams/element-internals-polyfill.git"

Diff for: src/element-internals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class ElementInternals implements IElementInternals {
142142
}
143143

144144
/** Sets the element's value within the form */
145-
setFormValue(value: string | FormData): void {
145+
setFormValue(value: string | FormData | null): void {
146146
const ref = refMap.get(this);
147147
throwIfNotFormAssociated(ref, `Failed to execute 'setFormValue' on 'ElementInternals': The target element is not a form-associated custom element.`);
148148
removeHiddenInputs(this);

Diff for: src/types.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,25 @@ export interface IAom {
4040
export interface IElementInternals extends IAom {
4141
checkValidity: () => boolean;
4242
form: HTMLFormElement;
43-
labels: NodeListOf<HTMLLabelElement>|[];
43+
labels: NodeListOf<HTMLLabelElement> | [];
4444
reportValidity: () => boolean;
45-
setFormValue: (value: string | FormData) => void;
46-
setValidity: (validityChanges: Partial<globalThis.ValidityState>, validationMessage?: string, anchor?: HTMLElement) => void;
45+
setFormValue: (value: string | FormData | null) => void;
46+
setValidity: (
47+
validityChanges: Partial<globalThis.ValidityState>,
48+
validationMessage?: string,
49+
anchor?: HTMLElement
50+
) => void;
4751
validationMessage: string;
4852
validity: globalThis.ValidityState;
4953
willValidate: boolean;
5054
}
5155

5256
export interface ICustomElement extends HTMLElement {
53-
attributeChangedCallback?: (name: string, oldValue: any, newValue: any) => void;
57+
attributeChangedCallback?: (
58+
name: string,
59+
oldValue: any,
60+
newValue: any
61+
) => void;
5462
connectedCallback?: () => void;
5563
disconnectedCallback?: () => void;
5664
attachedCallback?: () => void;
@@ -60,4 +68,8 @@ export interface ICustomElement extends HTMLElement {
6068
disabled?: boolean;
6169
}
6270

63-
export type LabelsList = NodeListOf<HTMLLabelElement>|[];
71+
export interface ILitElement extends ICustomElement {
72+
updateComplete: Promise<void>;
73+
}
74+
75+
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)