Skip to content

Commit 2ef92c9

Browse files
committed
wip
1 parent 09152c1 commit 2ef92c9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

packages/signals/signals/src/core/signal-generators/dom-gen/element-parser.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,33 @@ export const parseElement = (el: HTMLElement): AnyParsedElement => {
108108
const label = parseToLabel(labeledBy)
109109
labels.unshift(label)
110110
}
111+
111112
const parsedAttributes = parseNodeMap(el.attributes)
112113

113114
// This exists because of a bug in react-hook-form, where 'name', if used as the field registration name overrides the native element name value to reference itself.
114-
const getPropertyOrDefault = (prop: string) => {
115+
// This is a very weird scenario where a property was on the element, but not in the attributes map.
116+
// Only using this
117+
const getPropertyOrFallback = (prop: string): string | undefined => {
115118
if (!(prop in el)) {
116119
return undefined
117120
}
118121
// @ts-ignore
119122
const val = el[prop]
120-
return typeof val === 'string' ? val : parsedAttributes[prop] || undefined
123+
return typeof val === 'string' ? val : undefined
121124
}
122125

123126
const base: ParsedElementBase = {
124127
attributes: parsedAttributes,
125128
classList: [...el.classList],
126-
id: getPropertyOrDefault('id') || '',
129+
id: getPropertyOrFallback('id') || '',
127130
labels,
128131
label: labels[0],
129-
name: getPropertyOrDefault('name'),
132+
name: getPropertyOrFallback('name'),
130133
nodeName: el.nodeName,
131134
tagName: el.tagName,
132-
title: getPropertyOrDefault('title') || '',
133-
type: getPropertyOrDefault('type'),
134-
value: getPropertyOrDefault('value'),
135+
title: getPropertyOrFallback('title') || '',
136+
type: getPropertyOrFallback('type'),
137+
value: getPropertyOrFallback('value'),
135138
textContent: (el.textContent && cleanText(el.textContent)) ?? undefined,
136139
innerText: (el.innerText && cleanText(el.innerText)) ?? undefined,
137140
describedBy: (describedBy && parseToLabel(describedBy)) ?? undefined,

0 commit comments

Comments
 (0)