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 https://quasar.dev/options/platform-detection#Introduction, you can issue a check for
this.$q.platform.is.mobile
. -
@metalsadman
I don’t think that solves the issue. But I don’t know a Quasar way of doing this either.this.$q.platform.is.mobile
will return true for iPad Pro too which will show you the desktop drawer. The breakpoint is set on the drawer by a custom propertybreakpoint
.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 ?https://codepen.io/turigeza/pen/mdeMQaP?editors=1010
<!-- Forked from: https://quasar.dev/layout/drawer#Example--Mini-mode-with-click-trigger --> <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-toolbar> <q-btn flat @click="drawer = !drawer" round dense icon="menu"></q-btn> <q-toolbar-title>Header</q-toolbar-title> </q-toolbar> </q-header> <q-drawer v-model="drawer" show-if-above :mini="!drawer || miniState" @click.capture="drawerClick" :width="200" :breakpoint="500" bordered content-class="bg-grey-3" ref="drawer" > <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-section> <q-item-section> Inbox </q-item-section> </q-item> <q-item active clickable v-ripple> <q-item-section avatar> <q-icon name="star"></q-icon> </q-item-section> <q-item-section> Star </q-item-section> </q-item> <q-item clickable v-ripple> <q-item-section avatar> <q-icon name="send"></q-icon> </q-item-section> <q-item-section> Send </q-item-section> </q-item> <q-item clickable v-ripple> <q-item-section avatar> <q-icon name="drafts"></q-icon> </q-item-section> <q-item-section> Drafts </q-item-section> </q-item> </q-list> </q-scroll-area> <!-- 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"> <q-btn dense round unelevated color="accent" icon="chevron_left" @click="miniState = true" ></q-btn> </div> </q-drawer> <q-page-container> <q-page class="q-px-lg q-py-md"> <q-btn label="Is it belowBreakpoint?" @click="printRef"></q-btn> </q-page> </q-page-container> </q-layout> </div> </div>
new Vue({ el: '#q-app', data () { return { drawer: false, miniState: false } }, methods: { printRef(){ alert(this.$refs.drawer.belowBreakpoint); }, 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 e.stopPropagation() } } } })
-
turigeza that’s perfect! Thanks.