Skip to content

Commit

Permalink
feat: resolve v-model on radio element
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsn committed May 13, 2018
1 parent f83742f commit ce934b1
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/view/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ function resolveVModel(
}
return
}

if (type.value === 'radio') {
const valueAttr = attrs.find(a => !a.directive && a.name === 'value')
if (valueAttr) {
data.domProps!.checked = valueAttr.value === value
}
return
}
}
}
data.attrs!.value = value
Expand Down
27 changes: 27 additions & 0 deletions test/view/VueComponent/model.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,31 @@ describe('VueComponent v-model', () => {
expect(bar.checked).toBe(false)
expect(baz.checked).toBe(true)
})

it('resolves ratio button v-model', () => {
// prettier-ignore
const template = createTemplate([
h('div', [], [
h('input', [a('type', 'radio'), a('value', 'foo'), d('model', 'radio')], []),
h('input', [a('type', 'radio'), a('value', 'bar'), d('model', 'radio')], [])
])
])

const wrapper = render(
template,
[],
[
{
name: 'radio',
default: 'bar'
}
]
)

const foo = wrapper.find('input[value=foo]').element as HTMLInputElement
const bar = wrapper.find('input[value=bar]').element as HTMLInputElement

expect(foo.checked).toBe(false)
expect(bar.checked).toBe(true)
})
})

0 comments on commit ce934b1

Please sign in to comment.