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

close #13205
This commit is contained in:
edison 2025-05-20 08:43:51 +08:00 committed by GitHub
parent 013749e75e
commit 1a664749d4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View File

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

View File

@ -208,6 +208,20 @@ test('ATTR_FALSE_VALUE', () => {
).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", () => {
const vm = new Vue({
template: `<div :id="false" :foo="false"/>`,