[Feature Request] Slots for v-textarea and v-text-field
See original GitHub issueProblem to solve
This can be used to provide users with a quick way to input data without cluttering the ui. You are able to tag notes using #Important
, make links clickable within text fields and highlight special search terms like assigned-to:me
in a search inputs.
Proposed solution
Example:
<template>
<v-text-field v-model="text" :slots="slots">
<template slot="days" slot-scope="{ match, removeMatch, deleteText }">
<!-- removeMatch keeps the text but doesn't render the slot in its place (it will match again if the matched text changes (eg appending a "s" to "day")) -->
<v-chip @click="removeMatch">
<v-icon left>mdi-calendar-clock</v-icon>
<!-- match is the return value of RegExp.exec() -->
{{match[0]}}
<!-- deleteText removes the matched text -->
<v-icon right @click.stop="deleteText">mdi-close</v-icon>
</v-chip>
</template>
</v-text-field>
</template>
<script>
export default {
data() {
return {
text: "",
slots: [
{
// this slot will replace matched text with the component provided via slots ...
match: /\bin\s+(\d+)\sdays?\b/,
// ... only if this method returns true
verify(match) {
return Number(match[1]) < 100;
},
// the name of the slot
name: "days",
// limits the number of matches; if the user were to input "in 1 day" twice, only the latter occurence will be matched
limit: 1,
},
],
};
},
};
</script>
The result should look like this example from todoist:
removeMatch should work like this :
There is an example with <a :href="match[0]">{{match[0]}}</a>
as template:
Another example with a list of available values:
For this to work, an additional method getItems
has to be provided. The list itself should be similar to v-combobox
.
<script>
export default {
data() {
return {
text: "",
projects: [
// value will be inserted upon click, text will be displayed in the list (if no list-item slot is provided)
{ text: "Inbox", value: "#Inbox" },
{ text: "School", value: "#School" },
{ text: "Demo Project", value: "#Demo Project" },
],
slots: [
{
match: /\b#([\w\s])+\b/i,
verify(match) {
// only render the chip if the project exists
return !!this.projects.find(
(project) => project.value === match[1],
);
},
// all items to display in the list, can be customized using the list-item slot
getItems() {
return new Promise((resolve) => {
setTimeout(() => {
resolve(this.projects);
}, 500);
});
},
name: "project",
// no limit
limit: 0,
},
],
};
},
};
</script>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Extend vuetify VTextField - Stack Overflow
Scoped slots (e.g. append , append-outer ) will not output the expected element(s). So for this purpose, let's call this component " ...
Read more >Text field component - Vuetify
Icon slots. Instead of using prepend / append / append-outer icons you can use slots to extend input's functionality.
Read more >Issues · vuetifyjs/vuetify · GitHub
[Bug Report][2.6.7] VTextarea prop 'reverse' doesn't work correct in LTR direction ... [Feature Request] Slots for v-textarea and v-text-field C: VTextarea ...
Read more >How To Use V-Chips Inside Of V-Text-Field - ADocLib
[Feature Request] vselect auto width depending of content ... plain property for vbtn new slots for <vtextfield :disableddisabled></vtextfield> <vtextarea.
Read more >vuetify - Awesome JS
Features. proxiedModel: require event binding for controlled model (#15776) a01de65, ... VTextarea: align hint text with VTextField 428d6f3, closes #15618 ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://eager-elion-d7d275.netlify.app/ https://github.com/lukas-tr/vuetify-tiptap-example
@KaelWD Sounds cool. Can you direct us to some example or documentation please ?