-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Fix form property assignment edge case #35073
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
ab51bc1
to
8430313
Compare
setAttribute: (name: string, value: string) => void; | ||
} & Record<string, any> | ||
|
||
export function assignElementProperty(el: ElementWithAssignableProperties, kebabName: string, val: string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not Element
or HTMLElement
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't keyof typeof Element
work for the property access?
const camelizedName: keyof typeof Element = camelize(kebabName);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If not, use (el as any)[camelizedName] = ...
to assign. Better do dirty stuff within a function than to expose any
to consumers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see a clearer solution.
Feel free to edit this PR directly with your solution.
"form" has an edge case: its `<input name=action>` element overwrites the `action` property, we can only set attribute. This PR makes `assignElementProperty` can handle such case, and add more tests
"form" has an edge case: its
<input name=action>
element overwrites theaction
property, we can only set attribute.This PR makes
assignElementProperty
can handle such case, and add more tests