Przeglądaj źródła

fix(compat): ensure false value on input retains value attribute (#13216)

close #13205
edison 11 miesięcy temu
rodzic
commit
1a664749d4

+ 1 - 0
packages/runtime-dom/src/modules/attrs.ts

@@ -79,6 +79,7 @@ export function compatCoerceAttr(
     }
     }
   } else if (
   } else if (
     value === false &&
     value === false &&
+    !(el.tagName === 'INPUT' && key === 'value') &&
     !isSpecialBooleanAttr(key) &&
     !isSpecialBooleanAttr(key) &&
     compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
     compatUtils.isCompatEnabled(DeprecationTypes.ATTR_FALSE_VALUE, instance)
   ) {
   ) {

+ 14 - 0
packages/vue-compat/__tests__/misc.spec.ts

@@ -208,6 +208,20 @@ test('ATTR_FALSE_VALUE', () => {
   ).toHaveBeenWarned()
   ).toHaveBeenWarned()
 })
 })
 
 
+test('ATTR_FALSE_VALUE with false on input value', () => {
+  const vm = new Vue({
+    template: `<input :value="false"/>`,
+  }).$mount()
+  expect(vm.$el).toBeInstanceOf(HTMLInputElement)
+  expect(vm.$el.hasAttribute('value')).toBe(true)
+  expect(vm.$el.getAttribute('value')).toBe('false')
+  expect(
+    (deprecationData[DeprecationTypes.ATTR_FALSE_VALUE].message as Function)(
+      'value',
+    ),
+  ).not.toHaveBeenWarned()
+})
+
 test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
 test("ATTR_FALSE_VALUE with false value shouldn't throw warning", () => {
   const vm = new Vue({
   const vm = new Vue({
     template: `<div :id="false" :foo="false"/>`,
     template: `<div :id="false" :foo="false"/>`,