Built-in v-model
on <details>
and <dialog>
#495
Replies: 5 comments 3 replies
-
How about |
Beta Was this translation helpful? Give feedback.
-
Update: Implementation PR vuejs/core#8048 |
Beta Was this translation helpful? Give feedback.
-
Concerning What do you think about using a |
Beta Was this translation helpful? Give feedback.
-
As there are two states for the openness of these elements, they are similar to checkboxes from a data-binding perspective. For checkboxes, Vue supports various features beyond a basic boolean binding: e.g. |
Beta Was this translation helpful? Give feedback.
-
I've been thinking about a potential pattern with dialogs to support async reactivity awaiting the users confirmation. In this example, <script setup>
import { ref } from 'vue'
const show = ref(false)
const value = ref(null)
</script>
<dialog v-model="value" #default="{ internalValue }" modal :open="show">
<form method="dialog">
<input v-model="internalValue" />
<button value="cancel">Cancel</button>
<button>Confirm</button>
</form>
</dialog> This is considering the native dialog has a returnValue Handling this pattern with custom components would benefit from #523. Supporting the native dialog would need some sugar, and an intuitive way for the input's v-model of the temporary state for |
Beta Was this translation helpful? Give feedback.
-
Summary
Support built-in
v-model
binding for the native<details>
element and<dialog>
element.Links
v-model
on<details>
and<dialog>
#496v-model
for<details>
and<dialog>
core#8048Summary
Support built-in
v-model
binding for the native<details>
element and<dialog>
element.Basic example
When toggling the
<details>
or<dialog>
element, the value ofshow
should be reflected. Or onceshow
has been modified, the details should expand/collapse automatically.Motivation
Currently we support
v-model
built-in oninput
,textarea
,select
, which is convenient to bind the value to them. However, when it comes to<details>
and<dialog>
,v-model
will throw and users would need to bind manually. Which could be a bit counterintuitive.Since
<details>
and<dialog>
are native elements, it makes sense to have built-in support for them.For now, users would need to manually bind them as:
Detailed design
This is should be a compiler improvement, to be able to transform
v-model
on the<details>
and<dialog>
elements withopen
and@toggle
.Drawbacks
It might theoretically conflict if users managed to implement a nodeTransformer on the user land to support
v-model
on<details>
or<dialog>
. But we are not aware of any existing library doing this.Alternatives
N/A
Adoption strategy
This is a new feature and should not affect the existing code.
Unresolved questions
N/A
Beta Was this translation helpful? Give feedback.
All reactions