Best practice setting up q-scroll-area



  • I’m really struggling to get q-scroll-area to work reliably, and I’m sure I’m Doing It Wrong. The pattern I’ve been using is something like this:

    <template>
      <q-scroll-area class="fill-window">
        <div>
          <!-- Stuff here -->
        </div>
      </q-scroll-area>
    </template>
    
    <style scoped lang="stylus">
      .fill-window
        height calc(100vh - 160px)
    </style>
    

    This works, but (a) I’m hand tuning that offset (160px) to cater for the vertical position this component is rendered within the main layout, and (b) when I add something ‘optional’ to the component like this:

    <template>
      <q-scroll-area class="fill-window">
        <div v-if="showControls">
          <!-- Controls here -->
        </div>
        <div>
          <!-- Stuff here -->
        </div>
      </q-scroll-area>
    </template>
    

    The value of 160px now depends on whether the parent passed true or false to showControls.

    So, is there a better way to say “give as much height as possible without triggering the browsers own scrollbar”?



  • I made a codesandbox to illustrate the problem: https://codesandbox.io/embed/codesandbox-app-5g21z

    I would like the content in MyView to expand to fill the available space. That includes accounting for the variable sized controls on the parent view, which at the moment is done with a q-page-sticky (click the button to change its size), but I realise that will probably have to change. The 2 tabs show how not using any q-scroll-area means the entire page scrolls, and using a q-scroll-area with specific height ends up with cumbersome computed style="..." attributes.

    I suspect the main page will have to become a flex-column, but that’s a lot of refactoring in my app, and I wanted to be sure that was the right way to go and that I wasn’t missing something easy inside MyView.


Log in to reply