How to Create Comment Box using Flowbite Textarea in Vue 3

Last Updated on by in Vue JS

In this guide, you will learn how to create a simple comment box using Flowbite Textarea UI component in Vue with Tailwind CSS.

A Textarea is an essential UI component primarily used in user interfaces used to show multiline text input. It grants us to add and edit text that can spread over multiple lines.

We will show you how to create comment box using Textarea however Textarea can be used for: descriptions, messages, or any other type of text input where a single-line input field is not enough.

A Textarea is made of using multiple attributes:

id: A unique identification for the element.
name: Helps to identify the form field when the form is submitted.
rows: Allows to define the number of visible lines of text.
cols: Helps to add the number of visible columns of text.

Vue 3 Flowbite Textarea Comment Box Tutorial

  • Step 1: Build Vue App
  • Step 2: Add Flowbite Package
  • Step 3: Set up Tailwind CSS
  • Step 4: Create New Component
  • Step 5: Create Textarea Comment UI Component
  • Step 6: Update App Component
  • Step 7: Run Development Server

Build Vue App

Node js is a must have tool in regards to work in Vue environment. Node is a JavaScript run time environment, you can download it using the following link: https://nodejs.org/

After the node is installed, make sure to run the given command to install Vue CLI.

npm install -g @vue/cli

We are now ready to install the new Vue js application.

vue create vue-demo-app

Choose Vue 3 from the Vue CLI options.

Step inside the Vue project.

cd vue-demo-app

Add Flowbite Package

Here is the command that you can use to install the Vue Flowbite packages.

 npm install flowbite flowbite-vue --legacy-peer-deps

Set up Tailwind CSS

Tailwind is a super flexible UI development framework, you can use it to create beautiful and responsive user interfaces.

You have to add the given code in public/index.html file.

<!doctype html>
<html>
<head>
  ...
  ...

  <script src="https://cdn.tailwindcss.com"></script>
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            clifford: '#da373d',
          }
        }
      }
    }
  </script>
</head>
<body>
   
</body>
</html>

Create New Component

We are going to create a new Vue component, for that you have to make a components/TextareaComp.vue file.

<template>
    <div>
        
    </div>
</template>

<script>
export default {
    data() {
        return {
        }
    }
}
</script>

Create Textarea Comment UI Component

We defined the form component, within the form we created the template and added the Textarea to make the comment box.

Update following code in components/TextareaComp.vue file:

<template>
  <div>
    <form>
      <Textarea custom rows="3" placeholder="Write you message..." label="Your message">
        <template #footer>
          <div class="flex items-center justify-between">
            <Button type="submit">Post comment</Button>
            <div class="flex">
              <Button
                color=""
                class="rounded-lg hover:bg-gray-200 hover:dark:bg-gray-600"
                square
                ><svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="w-6 h-6"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M18.375 12.739l-7.693 7.693a4.5 4.5 0 01-6.364-6.364l10.94-10.94A3 3 0 1119.5 7.372L8.552 18.32m.009-.01l-.01.01m5.699-9.941l-7.81 7.81a1.5 1.5 0 002.112 2.13"
                  /></svg
              ></Button>
              <Button
                color=""
                class="rounded-lg hover:bg-gray-200 hover:dark:bg-gray-600"
                square
                ><svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="w-6 h-6"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M15 10.5a3 3 0 11-6 0 3 3 0 016 0z"
                  />
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M19.5 10.5c0 7.142-7.5 11.25-7.5 11.25S4.5 17.642 4.5 10.5a7.5 7.5 0 1115 0z"
                  /></svg
              ></Button>
              <Button
                color=""
                class="rounded-lg hover:bg-gray-200 hover:dark:bg-gray-600"
                square
                ><svg
                  xmlns="http://www.w3.org/2000/svg"
                  fill="none"
                  viewBox="0 0 24 24"
                  stroke-width="1.5"
                  stroke="currentColor"
                  class="w-6 h-6"
                >
                  <path
                    stroke-linecap="round"
                    stroke-linejoin="round"
                    d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z"
                  /></svg
              ></Button>
            </div>
          </div>
        </template>
      </Textarea>
    </form>
    <p class="ml-auto text-xs text-gray-500 dark:text-gray-400">
      Remember, contributions to this topic should follow our
      <a href="/" class="text-primary-600 dark:text-primary-500 hover:underline"
        >Community Guidelines</a
      >.
    </p>
  </div>
</template>

<script setup>
import { Button, Textarea } from "flowbite-vue";
</script>

Update App Component

In order to show the component on the browser, you required to add or import the component in the App.vue file;

<template>
  <div class="mx-auto max-w-2xl lg:max-w-5xl">
    <h2 class="text-2xl font-bold tracking-tight sm:text-3xl mb-6 mt-6">
      Vue Textarea Comment Box Component Example
    </h2>
    <TextareaComp />
  </div>
</template>

<script>
import TextareaComp from "./components/TextareaComp.vue";

export default {
  components: {
    TextareaComp,
  },
};
</script>

Run Development Server

We will now test the comment box, for that we have to run the Vue app using the given command:

npm run serve

After the development server started, type the given URL on the browser address bar and hit enter.

http://localhost:8080

How to Create Comment Box using Flowbite Textarea in Vue