question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature Request] Slots for v-textarea and v-text-field

See original GitHub issue

Problem 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:

vuetify feature 1 vuetify feature 2

removeMatch should work like this :

vuetify feature 4

There is an example with <a :href="match[0]">{{match[0]}}</a> as template:

vuetify feature 5

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>

vuetify feature 3

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:10
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Liwojcommented, Aug 24, 2021

@KaelWD Sounds cool. Can you direct us to some example or documentation please ?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found