Skip to content

Commit bee7632

Browse files
committed
docs: support v-model for dialog and details
1 parent ecff810 commit bee7632

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

src/api/built-in-directives.md

+2
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ Create a two-way binding on a form input element or a component.
351351
- `<input>`
352352
- `<select>`
353353
- `<textarea>`
354+
- `<details>`
355+
- `<dialog>`
354356
- components
355357

356358
- **Modifiers:**

src/guide/essentials/forms.md

+72-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ const checkedNames = ref([])
1111
const picked = ref('')
1212
const selected = ref('')
1313
const multiSelected = ref([])
14+
const detailsOpen = ref(false)
15+
const dialogOpen = ref(false)
1416
</script>
1517

1618
# Form Input Bindings {#form-input-bindings}
@@ -266,8 +268,6 @@ Single select:
266268

267269
[Try it in the Playground](https://play.vuejs.org/#eNp1j1ELgyAUhf/KxZe2h633cEHbHxjstReXdxCYSt5iEP333XIJPQSinuN3jjqJyvvrOKAohAxN33oqa4tf73oCjR81GIKptgBakTqd4x6gRxp6uymAgAYbQl1AlkVvXhaeeMg8NbMg7LxRhKwAZPDKlvBK8WlKXTDPnFzOI7naMF46p9HcarFxtVgBRpyn1lnQbVBvwwWjMgMyycTToAr47wZnUeaR3mfL6sC/H/iPnc/vXS9gIfP0UTH/ACgWeYE=)
268270

269-
</div>
270-
271271
:::tip Note
272272
If the initial value of your `v-model` expression does not match any of the options, the `<select>` element will render in an "unselected" state. On iOS this will cause the user not being able to select the first item because iOS does not fire a change event in this case. It is therefore recommended to provide a disabled option with an empty value, as demonstrated in the example above.
273273
:::
@@ -360,6 +360,76 @@ export default {
360360

361361
</div>
362362

363+
### Details {#details}
364+
365+
```vue-html
366+
<div>Open: {{ open }}</div>
367+
368+
<details v-model="open">
369+
<summary>This is summary</summary>
370+
<p>And this is more detailed explanation.</p>
371+
</details>
372+
```
373+
374+
<div class="demo">
375+
<div>Open: {{ detailsOpen }}</div>
376+
377+
<details v-model="detailsOpen">
378+
<summary>This is summary</summary>
379+
<p>And this is more detailed explanation.</p>
380+
</details>
381+
</div>
382+
383+
<div class="composition-api">
384+
385+
[Try it in the Playground](https://play.vuejs.org/#eNo9j8EKwjAMhl8l9KIetHepA5/Ai8deypZhYU1Lmw1l7N1NXRFy+ZPv/5Os6p7SZZlRXZUpffaJoSDPqbPkQ4qZYYWMI2ww5hjgIOjBkqU+UmGICQluFTiObip4smT0HiMBIhhDmhyjKAAz+KV7iOUK67p7t83o2q1wBZCdnwos5xAHnG5WVcqqn13mZQ7B5U/3fPkCUk3LzjZoXOruNAA3KsSMsEfjAPiWi8ixj3Qxuj4qBt02izL6f7Tavi1xZNY=)
386+
387+
</div>
388+
<div class="options-api">
389+
390+
[Try it in the Playground](https://play.vuejs.org/#eNo9T8uuAjEI/RXS1b0L7d7USfwCNy5nQyzGJn2lZSaayfy7dKaaEODA4QCLuuR8nCdSJ2XqvbjMwxjplVNhsPTAyTMsYwSwyPj3v+cAhXgq8YsAUqZ4ggf6SntpbUGcmNE/YQFMIXtkEgRgrJuH6za7LJsIrKvRrdrIjUCMzleYDyFZ8udRNdaotnHp1ykELO/h9nQVxDqWnb3ReXm4RAvcWSEVkveaNFmQdz1GZJfi0ei8X6b7ZkFG/45W6wc1S2it)
391+
392+
</div>
393+
394+
### Dialog {#dialog}
395+
396+
```vue-html
397+
<button @click="open = !open">
398+
Open: {{ open }}
399+
</button>
400+
401+
<dialog v-model="open">
402+
<form type="dialog">
403+
<p>Dialog content</p>
404+
<button type="submit">OK</button>
405+
</form>
406+
</dialog>
407+
```
408+
409+
<div class="demo">
410+
<button @click="dialogOpen = !dialogOpen">
411+
Open: {{ dialogOpen }}
412+
</button>
413+
414+
<dialog v-model="dialogOpen">
415+
<form type="dialog">
416+
<p>Dialog content</p>
417+
<button type="submit">OK</button>
418+
</form>
419+
</dialog>
420+
</div>
421+
422+
<div class="composition-api">
423+
424+
[Try it in the Playground](https://play.vuejs.org/#eNpNj81qwzAQhF9lq0vaQ6t7UEILveWQF9DFcdZBRD+LtA4E43fP2hImJzHMzKedSf0R/TxGVHtlSp8dMRTkkY42ukApM0yQcYAZhpwC7CS6s9HGPsXCkAgjHJbA59D5gl82Gl0xAhDBGMh3jKIAzGVkThF+e+/6+8GqVv9YXqvWDMBZxB6mqcLneW3qWl2hIq+u8+kGj++QrugbaSOYIeUA/CQUp0Y3T1w6/te6bGCMbPSytpntxFYu4yU4lvL59HbCGtTLJ3WWrn+IMHobrOYXGf10wg==)
425+
426+
</div>
427+
<div class="options-api">
428+
429+
[Try it in the Playground](https://play.vuejs.org/#eNpNT0FuwyAQ/MqUU3touUckaqXeesgHfCH2urKKAeElamX5712D40RCLMPszOzO6iPGt2smdVBmatMQ+dR4+o0hMTrqbXaMufFAZ9k+v9Q3kIhz8jcEhEj+gN66ierXsha55Bi9GwtgGqOzTIIAc8nMweO9dUP7c2zU6oMjntbaqNIDnIv5PJcULMXa6CotpgK7wbrwjevrGDpym9PuYPqQRvBfJGFq684JG0+fVd4Gz+TZ6HgntxE38ZQv48AiPn89jFAa9RpS19I1Q4DR+8Jq+QcISniZ)
430+
431+
</div>
432+
363433
## Value Bindings {#value-bindings}
364434

365435
For radio, checkbox and select options, the `v-model` binding values are usually static strings (or booleans for checkbox):

0 commit comments

Comments
 (0)