Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make v-tabs-items and v-tab-item fill height

I am following the example: https://vuetifyjs.com/en/components/tabs#content

<v-tabs-items v-model="model">
    <v-tab-item
      v-for="i in 3"
      :key="i"
      :value="`tab-${i}`"
    >
      <v-card flat>
        <v-card-text v-text="text"></v-card-text>
      </v-card>
    </v-tab-item>
  </v-tabs-items>

However, I want v-card to take the rest of height. How can I achieve it?

like image 736
RX Forces Avatar asked Dec 10 '22 03:12

RX Forces


1 Answers

I ran into this problem today. One possible solution that worked for me was to figure out the hierarchy of classes that are generated by vuetify, using the inspector, and then hack the css for those specific classes. This was based on the recommendation in this SO answer which suggests to modify the height of .v-tabs__content. Unfortunately that class no longer seems to exist and instead (in the example you posted) the generated hierarchy is something along the lines of

<div>
<!-- Top level container of the tabbed interface -->
  <nav>
    <!-- Toolbar and tab header generated here -->
  </nav>
  <div class="v-window">
    <div class="v-window__container">
      <div class="v-window-item">
        <div class="v-card">
          <div class="v-card__text">Text.</div>
        </div>
      </div>
    </div>
  </div>
</div>

So, it is necessary to modify the css height of v-window, v-window__container, and v-window-item to make sure the tab content container stretches to the size of its parent as desired. Finally, we need to change the height of the internal content, in this case the v-card.

In my code I ended up also setting display:flex for the container wrapper, and flex only for the .v-window. Using flex ensures everything aligns correctly below the toolbar and finally ensures the correct stretched height for the tab content.

Here is a codepen with my solution https://codepen.io/anon/pen/wNEOdy, adapted for the example you posted.

HTML:

<div id="app">
  <v-app id="inspire">
    <div class="tab-wrapper">
      <v-toolbar
        color="cyan"
        dark
        tabs
      >
        <v-toolbar-side-icon></v-toolbar-side-icon>

        <v-toolbar-title>Page title</v-toolbar-title>

        <v-spacer></v-spacer>

        <v-btn icon>
          <v-icon>search</v-icon>
        </v-btn>

        <v-btn icon>
          <v-icon>more_vert</v-icon>
        </v-btn>

        <v-tabs
          slot="extension"
          v-model="model"
          centered
          color="cyan"
          slider-color="yellow"
        >
          <v-tab
            v-for="i in 3"
            :key="i"
            :href="`#tab-${i}`"
          >
            Item {{ i }}
          </v-tab>
        </v-tabs>
      </v-toolbar>

      <v-tabs-items v-model="model">
        <v-tab-item
          v-for="i in 3"
          :key="i"
          :value="`tab-${i}`"
        >
          <v-card flat>
            <v-card-text v-text="text"></v-card-text>
          </v-card>
        </v-tab-item>
      </v-tabs-items>
    </div>
  </v-app>
</div>

CSS:

.tab-wrapper {
  height:100%; /* Set to desired height of entire tabbed section, or use flex, or ... */
  display:flex; 
  flex-direction: column;
}

.tab-wrapper .v-window{
  flex: 1;
}

.tab-wrapper .v-window__container,
.tab-wrapper .v-window-item  {
  height: 100%;
}

/* customise the dimensions of the card content here */
.tab-wrapper .v-card {
  height: 100%;
}

JS:

new Vue({
  el: '#app',
  data () {
    return {
      model: 'tab-2',
      text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.'
    }
  }
})
like image 166
amatyjajo Avatar answered Dec 14 '22 15:12

amatyjajo