Skip to content

Commit 5dbe746

Browse files
authored
pininput: fix callstack overflow on input (#158)
1 parent b9ede77 commit 5dbe746

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

.changeset/shy-seahorses-kick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"melt": patch
3+
---
4+
5+
pininput: fix callstack overflow on input

packages/melt/src/lib/builders/PinInput.svelte.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ import type { Extracted, MaybeGetter } from "$lib/types";
33
import { dataAttr, disabledAttr } from "$lib/utils/attribute";
44
import { inBrowser } from "$lib/utils/browser";
55
import { extract } from "$lib/utils/extract";
6-
import { createDataIds, createId } from "$lib/utils/identifiers";
6+
import { createBuilderMetadata } from "$lib/utils/identifiers";
77
import { isHtmlInputElement } from "$lib/utils/is";
88
import type { HTMLInputAttributes } from "svelte/elements";
99

10-
const identifiers = createDataIds("pin-input", ["root", "input"]);
11-
10+
const { dataAttrs, dataSelectors, createIds } = createBuilderMetadata("pin-input", ["root", "input"])
1211
export type PinInputError = {
1312
method: "paste" | "input";
1413
message: string;
@@ -122,7 +121,7 @@ function setInputSelectionRange(input: HTMLInputElement, start: number, end: num
122121
}
123122

124123
export class PinInput {
125-
#id = createId();
124+
#ids = createIds();
126125

127126
/* Props */
128127
#props!: PinInputProps;
@@ -143,15 +142,16 @@ export class PinInput {
143142
value: props.value,
144143
onChange: props.onValueChange,
145144
defaultValue: "",
145+
equalityCheck: true,
146146
});
147147
this.#props = props;
148148
}
149149

150150
#getInputEls(): HTMLInputElement[] {
151151
if (!inBrowser()) return [];
152-
const rootEl = document.getElementById(this.#id);
152+
const rootEl = document.getElementById(this.#ids.root);
153153
if (!rootEl) return [];
154-
return [...rootEl.querySelectorAll(`[${identifiers.input}]`)].filter(isHtmlInputElement);
154+
return [...rootEl.querySelectorAll(dataSelectors.input)].filter(isHtmlInputElement);
155155
}
156156

157157
get value() {
@@ -176,8 +176,8 @@ export class PinInput {
176176
/** The root element's props. */
177177
get root() {
178178
return {
179-
[identifiers.root]: "",
180-
id: this.#id,
179+
[dataAttrs.root]: "",
180+
id: this.#ids.root,
181181
"data-complete": dataAttr(this.isFilled),
182182
} as const;
183183
}
@@ -234,7 +234,7 @@ export class PinInput {
234234
};
235235

236236
return {
237-
[identifiers.input]: "",
237+
[dataAttrs.input]: "",
238238
placeholder: isFocused ? undefined : this.placeholder,
239239
disabled: disabledAttr(this.disabled),
240240
type: this.mask ? "password" : "text",

0 commit comments

Comments
 (0)