Search code examples
cssvue.jsflexboxvuetify.jsword-wrap

Word Wrapping with vuetify, flexbox, and lists


I have a flexbox with the v-list. My problem is that there is some text in the v-list which is not wrapping. I see the following:

enter image description here

It appears the part that contains the list just grows unbounded in width and that is why it won't wrap.

I have a CodePen at https://codepen.io/james-hudson3010/pen/GRobYRo which demonstrates the problem.

JAVASCRIPT:

new Vue({
  el: '#app',
  vuetify: new Vuetify(),
  props: {
    source: String,
  },

  data: () => ({
    selectedItem: null,
    flattened: [
      {
        'name': 'item 3 title content',
        'comment': 'this is a really long comment to see what will happen with the text. I would like this text to wrap, but I am pretty sure it will not do that yet. This is just a test to see what is going to happen as it grows really long. Will this text ever wrap.'
      }      
    ]
  }),
})

HTML:

<div id="app">
  <v-app id="inspire">
    <div class="d-flex flex-row align-stretch" style="width: 100%;">
      <div style="background-color: red; width: 500px">
        <v-btn class="ma-4">A button</b-btn>
      </div>
      <v-card style="background-color: lightgreen" style="width: 100%">
        <v-list dense flat color="transparent" >
          <v-list-item-group v-model="selectedItem">
            <v-list-item v-for="item in flattened" :key="item.id">
                <v-list-item-content>
                  <v-list-item-title v-text="item.name"></v-list-item-title>
                  <v-list-item-subtitle style="overflow-wrap: break-word;" v-text="item.comment"></v-list-item-subtitle>
                </v-list-item-content>
            </v-list-item>
        </v-list-item-group>         
       </v-list>     
    </v-card>
  </v-app>
</div>

What needs to change for the text to wrap correctly?


Solution

  • Add built-in text-wrap class:

     <v-list-item-subtitle class="text-wrap" v-text="item.comment"></v-list-item-subtitle>