Skip to content
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

fix: input's value is string when passing number #7182

Merged
merged 17 commits into from
Jan 12, 2025
2 changes: 1 addition & 1 deletion packages/qwik/src/core/shared/jsx/types/jsx-generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ type SpecialAttrs = {
* For type: HTMLInputTypeAttribute, excluding 'button' | 'reset' | 'submit' | 'checkbox' |
* 'radio'
*/
'bind:value'?: Signal<string | undefined>;
'bind:value'?: Signal<string | undefined | number>;
enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send' | undefined;
height?: Size | undefined;
max?: number | string | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/qwik/src/core/shared/utils/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const stringifyStyle = (obj: any): string => {
};

export const serializeBooleanOrNumberAttribute = (value: any) => {
return value != null ? String(value) : null;
return value != null ? (typeof value === 'number' ? value : String(value)) : null;
};

export function serializeAttribute(
Expand Down
9 changes: 6 additions & 3 deletions packages/qwik/src/server/ssr-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1181,17 +1181,20 @@ class SSRContainer extends _SharedContainer implements ISSRContainer {
key = QContainerAttr;
value = QContainerValue.TEXT;
}

const serializedValue = serializeAttribute(key, value, styleScopedId);

if (serializedValue != null && serializedValue !== false) {
this.write(' ');
this.write(key);
if (serializedValue !== true) {
if (typeof serializedValue === 'number') {
this.write('=');
const strValue = escapeHTML(serializedValue);
this.write(strValue);
this.write('');
} else if (serializedValue !== true) {
this.write('="');
const strValue = escapeHTML(String(serializedValue));
this.write(strValue);

this.write('"');
}
JerryWu1234 marked this conversation as resolved.
Show resolved Hide resolved
}
Expand Down
Loading