]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-dom): also set attribute for form element state
authorEvan You <yyx990803@gmail.com>
Fri, 31 May 2024 15:22:42 +0000 (23:22 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 31 May 2024 15:22:42 +0000 (23:22 +0800)
close #6007
close #6012

packages/runtime-dom/src/modules/attrs.ts
packages/runtime-dom/src/patchProp.ts

index ff3ce36bf52b9d75e9020f6b721624a15becbbc0..8d8c10c31bf391c60335d1fc6aca5b34ce97c50b 100644 (file)
@@ -18,6 +18,7 @@ export function patchAttr(
   value: any,
   isSVG: boolean,
   instance?: ComponentInternalInstance | null,
+  isBoolean = isSpecialBooleanAttr(key),
 ) {
   if (isSVG && key.startsWith('xlink:')) {
     if (value == null) {
@@ -32,7 +33,6 @@ export function patchAttr(
 
     // note we are only checking boolean attributes that don't have a
     // corresponding dom prop of the same name here.
-    const isBoolean = isSpecialBooleanAttr(key)
     if (value == null || (isBoolean && !includeBooleanAttr(value))) {
       el.removeAttribute(key)
     } else {
index ef0197ed23c63c0ffa9955c4a80f2848434ee89e..0da0ff1f272a82be08d09d5607781e47c649b1ce 100644 (file)
@@ -52,6 +52,11 @@ export const patchProp: DOMRendererOptions['patchProp'] = (
       parentSuspense,
       unmountChildren,
     )
+    // #6007 also set form state as attributes so they work with
+    // <input type="reset"> or libs / extensions that expect attributes
+    if (key === 'value' || key === 'checked' || key === 'selected') {
+      patchAttr(el, key, nextValue, isSVG, parentComponent, key !== 'value')
+    }
   } else {
     // special case for <input v-model type="checkbox"> with
     // :true-value & :false-value