Preloader
Vue.js 2
  • Estimated reading time: 1 Minute

What's the equivalent to optgroup selects in Vuetify

What's the equivalent to optgroup selects in Vuetify

The optgroup tag in HTML is used to group related options in your select elements in the webpage. For example, if the user has to select a theme for an editor, it would be great if the themes were grouped by Dark and Light themes right? In Vuetify it isn't so intuitive to implement such a feature and differs a little bit from what you would expect to implement it. Instead of having an object whose keys are the labels of every optgroup and the items are the options in the Select, in Vuetify all of the elements should be inside the same array. To simulate an optgroup, you will need to add a new object that has the header key set (its value will be used as text of the optgroup) as specified in the official documentation.

For example:

<template>
    <v-select
        item-text="name"
        item-value="themeFile"
        v-model="theme"
        :items="themes"
    ></v-select>
</template>
<script>
    export default {
        props: ["dialog"],
        data() {
            return {
                theme: null,
                themes: [
                    // Add Optgroup option (Dark Themes)
                    { header: "Dark Themes" },
                    { name: "Night Bright", themeFile: "night-bright.css" },
                    { name: "Dracula", themeFile: "dracula.css" },
                    // Add Optgroup option (Light Themes)
                    { header: "Light Themes" },
                    { name: "Day Bright", themeFile: "day-bright.css" },
                    { name: "Blue", themeFile: "blue.css" }
                ]
            };
        }
    };
</script>

Happy coding ❤️!

Share:
Carlos Delgado

Carlos Delgado

Senior Software Engineer at Software Medico. Interested in programming since he was 14 years old, Carlos is a self-taught programmer and founder and author of most of the articles at Our Code World.

Related articles
How to use a button as a file uploader with Vuetify in Vue.js
28 Oct, 2021
  • Estimated reading time: 1 Minute
How to use Web Workers in Vue.js
27 Jul, 2021
  • Estimated reading time: 7 Minutes
How to disable swiping on Vuetify Tabs
27 Jul, 2021
  • Estimated reading time: 1 Minute
How to disable the prefetch plugin in Vue.js 2
21 Jul, 2021
  • Estimated reading time: 12 Minutes
How to copy text to the clipboard in Vue.js 2
16 Dec, 2020
  • Estimated reading time: 2 Minutes
Weekly trending
How Smart Tech Helps Minimize Home Water Waste
16 Jun, 2026
  • Estimated reading time: 6 Minutes
How to Integrate Zendesk With NetSuite
16 Jun, 2026
  • Estimated reading time: 5 Minutes
The Convergence of AI, Cybersecurity & Modern Web Development | OST
16 Jun, 2026
  • Estimated reading time: 4 Minutes
The Impact of Technology on Packaging Operations: Complete Guide
15 Jun, 2026
  • Estimated reading time: 5 Minutes
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.