Skip to content

Commit c78ed4e

Browse files
38elementseddyerburgh
authored andcommitted
docs: improve document for setChecked(), setSelected() and setValue() (#728)
1 parent b14afae commit c78ed4e

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

Diff for: docs/api/wrapper/setChecked.md

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
## setChecked(value)
1+
## setChecked(checked)
22

3-
Sets the value of a radio or checkbox `<input>`.
3+
Sets checked value for input element of type checkbox or radio and updates `v-model` bound data.
44

55
- **Arguments:**
6-
- `{Boolean} selected`
6+
- `{Boolean} checked (default: true)`
77

88
- **Example:**
99

@@ -16,3 +16,14 @@ const option = wrapper.find('input[type="radio"]')
1616
option.setChecked()
1717
```
1818

19+
- **Note:**
20+
21+
When you try to set the value to state via `v-model` by `radioInput.element.checked = true; radioInput.trigger('input')`, `v-model` is not triggered. `v-model` is triggered by `change` event.
22+
23+
`checkboxInput.setChecked(checked)` is an alias of the following code.
24+
25+
```js
26+
checkboxInput.element.checked = checked
27+
checkboxInput.trigger('click')
28+
checkboxInput.trigger('change')
29+
```

Diff for: docs/api/wrapper/setSelected.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
## setSelected(value)
1+
## setSelected()
22

3-
Sets a specified `<option>` as selected in a `<select>`.
4-
5-
- **Arguments:**
6-
- `{Boolean} selected`
3+
Selects an option element and updates `v-model` bound data.
74

85
- **Example:**
96

@@ -15,5 +12,15 @@ const wrapper = shallowMount(Foo)
1512
const options = wrapper.find('select').findAll('option')
1613

1714
options.at(1).setSelected()
18-
expect(wrapper.text()).to.contain('option1')
15+
```
16+
17+
- **Note:**
18+
19+
When you try to set the value to state via `v-model` by `option.element.selected = true; parentSelect.trigger('input')`, `v-model` is not triggered. `v-model` is triggered by `change` event.
20+
21+
`option.setSelected()` is an alias of the following code.
22+
23+
```js
24+
option.element.selected = true
25+
parentSelect.trigger('change')
1926
```

Diff for: docs/api/wrapper/setValue.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## setValue(value)
22

3-
Sets the value of a text `<input>`.
3+
Sets value of a text-control input element and updates `v-model` bound data.
44

55
- **Arguments:**
66
- `{String} value`
@@ -15,3 +15,12 @@ const wrapper = mount(Foo)
1515
const input = wrapper.find('input[type="text"]')
1616
input.setValue('some value')
1717
```
18+
19+
- **Note:**
20+
21+
`textInput.setValue(value)` is an alias of the following code.
22+
23+
```js
24+
textInput.element.value = value
25+
textInput.trigger('input')
26+
```

0 commit comments

Comments
 (0)