Skip to content

Commit

Permalink
fix(runtime-dom): use Symbol value for checkbox true-value vuejs#10597
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei committed Mar 28, 2024
1 parent db374e5 commit a127b8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/runtime-dom/__tests__/patchAttrs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,12 @@ describe('runtime-dom: attrs patching', () => {
patchProp(el, 'onwards', 'a', null)
expect(el.getAttribute('onwards')).toBe(null)
})

// #10597
test('should allow setting attribute to symbol', () => {
const el = document.createElement('div')
const symbol = Symbol('foo')
patchProp(el, 'foo', null, symbol)
expect(el.getAttribute('foo')).toBe(symbol.toString())
})
})
3 changes: 2 additions & 1 deletion packages/runtime-dom/src/modules/attrs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export function patchAttr(
if (value == null || (isBoolean && !includeBooleanAttr(value))) {
el.removeAttribute(key)
} else {
el.setAttribute(key, isBoolean ? '' : value)
// attribute value is a string https://html.spec.whatwg.org/multipage/dom.html#attributes
el.setAttribute(key, isBoolean ? '' : String(value))
}
}
}
Expand Down

0 comments on commit a127b8d

Please sign in to comment.