Skip to content

useSidebar ​

Manages the full sidebar state: open/close, rail mode, expand-on-hover behaviour, drag-to-resize, and user preference persistence.

File: vue/src/js/hooks/useSidebar.js


Usage ​

js
import { useSidebar } from '@/hooks'

const {
  status,
  rail,
  width,
  options,
  expandHover,
  handleRailToggle,
  handleResizeStart,
  handleResizing,
  handleResizeEnd,
  handleSidebarLeave
} = useSidebar()
html
<v-navigation-drawer
  v-model="status"
  :rail="rail"
  :width="width"
  :permanent="effectivePermanent"
  :temporary="effectiveTemporary"
  @mousedown.native="handleResizeStart"
>
  ...
</v-navigation-drawer>

Returns ​

State ​

NameTypeDescription
statusComputedRef<Boolean>Sidebar open/closed (read/write — synced with Vuex config.sidebarStatus)
railComputedRef<Boolean>True when in rail (mini) mode on lgAndUp
railManualRef<Boolean>Local rail toggle state (persisted to user prefs)
widthComputedRef<Number>Current sidebar width in px
railWidthComputedRef<Number>Rail-mode width (default 56)
optionsComputedRef<Object>Merged config + user preferences for the sidebar
expandHoverComputedRef<String>'mini' | 'hidden' — expand-on-hover strategy
fullyHiddenComputedRef<Boolean>True when expandHover === 'hidden'
sidebarLocationComputedRef<String>'left' or 'right'
hideIconsComputedRef<Boolean>True when not in rail and options.hideIcons is set
isHoverableComputedRef<Boolean>True when expand-on-hover is active
sidebarPinnedComputedRef<Boolean>Whether the user has pinned the sidebar open
effectivePersistentComputedRef<Boolean>Whether the sidebar participates in Vuetify layout (narrows main content)
effectivePermanentComputedRef<Boolean>Always visible and layout-aware on desktop in mini mode
effectiveTemporaryComputedRef<Boolean>Overlay mode (does not affect main content width)
isResizingRef<Boolean>True while the user is dragging the resize handle
openArrayOpen state for nested navigation groups
activeMenuComputedRef<String>Active menu item anchor (e.g. '#profile')

Methods ​

NameSignatureDescription
handleRailToggle() => voidToggle rail mode and persist the preference
handleResizeStart(e) => voidBegin drag resize (mousedown on the resize handle)
handleResizing(e) => voidUpdate sidebar width during drag (mousemove)
handleResizeEnd() => voidFinish resize and persist the new width
handleSidebarLeave() => voidClose the sidebar when in hidden mode and not pinned
handleMenu(title) => voidSet activeMenu to #title
handleProfile(event) => voidExpand profile section on hover if expandOnHover is configured

Expand strategies ​

expandHoverBehaviour
'mini'Sidebar is always visible (rail or expanded). Toggling rail narrows/expands while the sidebar stays in the Vuetify layout.
'hidden'Sidebar is an overlay. It appears on hover over the left edge or when opened programmatically. Pinning it makes it persistent.

Drag-to-resize ​

The resize handle triggers handleResizeStart (mousedown). Global mousemove / mouseup listeners (added in onMounted) call handleResizing and handleResizeEnd. The width is clamped to [256, 400] px and persisted via useNavigationLayout.persistUiPreferences.

See Also ​

  • useNavigationLayout — topbar and bottom-nav config merging; provides persistUiPreferences