Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lukas-tr opened this issue Mar 24, 2019 · 15 comments
Open

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

lukas-tr opened this issue Mar 24, 2019 · 15 comments
Assignees
Milestone

Comments

@lukas-tr
Copy link

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

@MajesticPotatoe MajesticPotatoe added C: VTextarea VTextarea C: VTextField VTextField T: feature A new feature labels Apr 9, 2019
@Franco-gario
Copy link

This, i need this.

Did you find any workaround to achieve what you are showing in the gifs?

@lukas-tr
Copy link
Author

This, i need this.

Did you find any workaround to achieve what you are showing in the gifs?

No, the gifs are recorded from https://todoist.com

@Franco-gario
Copy link

This, i need this.
Did you find any workaround to achieve what you are showing in the gifs?

No, the gifs are recorded from https://todoist.com

Thank you for you quick answer.
Unfortunately I could not find a workaround either.
Let's hope they implement it!

Regards

@denmasyarikin
Copy link

I need it too for google place autocomplete, any suggestion?

@lukas-tr
Copy link
Author

I need it too for google place autocomplete, any suggestion?

Seems like https://vuetifyjs.com/en/components/autocompletes/#asynchronous-items might do the job.

@egeersoz

This comment has been minimized.

@lukas-tr
Copy link
Author

lukas-tr commented Mar 3, 2021

We ended up using tiptap in the meantime. https://tiptap.dev/suggestions

@johnleider johnleider added the maybe Functionality that we are considering label Jul 14, 2021
@johnleider johnleider added this to the v3.0.0 milestone Jul 15, 2021
@johnleider johnleider added this to To do in Vuetify 3 - Titan via automation Jul 15, 2021
@johnleider johnleider added Vuetify 3 - Phase 3 and removed maybe Functionality that we are considering labels Jul 16, 2021
@lukas-tr
Copy link
Author

Might be a little late, but tiptap allows you to render arbitrary Vue components within the editor. Together with a slightly modified version of @tiptap/extension-mention and some input rules, I can create exactly what I showed in the gifs. It's more work to integrate than my proposed solution, but on the other hand it's way more customizable.

Demos
https://www.tiptap.dev/examples/interactivity
https://www.tiptap.dev/guide/node-views/

@egeersoz

This comment has been minimized.

@KaelWD
Copy link
Member

KaelWD commented Aug 4, 2021

I think we'll just recommend using tiptap for this, it's a pretty complex feature and seems to have been done well already. In Vuetify 3 it should be fairly easy to integrate with the v-input styles: #13554

@lukas-tr
Copy link
Author

lukas-tr commented Aug 5, 2021

@lukas-tr Mind sharing codepen examples?

https://eager-elion-d7d275.netlify.app/ https://github.com/lukas-tr/vuetify-tiptap-example

@Shinigami92
Copy link
Contributor

I also need this feature, but the tiptap example doesn't fulfill my needs due to it is not a v-text-field anymore. But I need all the other stuff like :rules, :placeholder, outlined, :counter ...
Also I just need an input, not a textarea.

@KaelWD
Copy link
Member

KaelWD commented Aug 24, 2021

@Shinigami92 Vuetify 3 allows you to use tiptap but with all the v-text-field styles. There isn't a good example currently but you would put an unstyled tiptap inside VField inside VInput.
https://vuetifyjs.com/en/components/inputs/

@Liwoj
Copy link

Liwoj commented Aug 24, 2021

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

@lokeswari9

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

10 participants