How can javascript test whether q-drawer is in mobile state?

  • My left drawer has a button to toggle mini mode on/off. But in mobile state, mini has no effect.
    I want to re-purpose the button to hide the drawer.
    How can I test whether we’re in mobile state or not?
    I know there’s a CSS class which is active in mobile, but I don’t know how to test for this since I can’t get the ‘drawer’ element as a ref.

  • @CWoodman use platform detection plugin, you can issue a check for this.$

  • @metalsadman
    I don’t think that solves the issue. But I don’t know a Quasar way of doing this either. this.$ will return true for iPad Pro too which will show you the desktop drawer. The breakpoint is set on the drawer by a custom property breakpoint .

    I guess you could check the screen width and compare it your set breakpoint … sort of a hack.

  • Drawer seems to have a property belowBreakpoint. Which you could use to determine if the drawer is in belowBreakpoint. I presume this is what you mean when you say in mobile state. But you have to reference the drawer I don’t know why you can not reference the drawer ?

      Forked from:
    <div id="q-app">
      <div class="q-pa-md">
        <q-layout view="hHh Lpr lff" container style="height: 300px" class="shadow-2 rounded-borders">
          <q-header elevated class="bg-black">
              <q-btn flat @click="drawer = !drawer" round dense icon="menu"></q-btn>
            :mini="!drawer || miniState"
            <q-scroll-area class="fit">
              <q-list padding>
                <q-item clickable v-ripple>
                  <q-item-section avatar>
                    <q-icon name="inbox"></q-icon>
                <q-item active clickable v-ripple>
                  <q-item-section avatar>
                    <q-icon name="star"></q-icon>
                <q-item clickable v-ripple>
                  <q-item-section avatar>
                    <q-icon name="send"></q-icon>
                <q-item clickable v-ripple>
                  <q-item-section avatar>
                    <q-icon name="drafts"></q-icon>
              in this case, we use a button (can be anything)
              so that user can switch back
              to mini-mode
            <div class="q-mini-drawer-hide absolute" style="top: 15px; right: -17px">
                @click="miniState = true"
            <q-page class="q-px-lg q-py-md">
              <q-btn label="Is it belowBreakpoint?" @click="printRef"></q-btn>
    new Vue({
      el: '#q-app',
      data () {
        return {
          drawer: false,
          miniState: false
      methods: {
        drawerClick (e) {
          // if in "mini" state and user
          // click on drawer, we switch it to "normal" mode
          if (this.miniState) {
            this.miniState = false
            // notice we have registered an event with capture flag;
            // we need to stop further propagation as this click is
            // intended for switching drawer to "normal" mode only

  • turigeza that’s perfect! Thanks.

Log in to reply