Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:0xranx OpenContext useTauriDrag

From Leeroopedia
Knowledge Sources
Domains Window_Management, React
Last Updated 2026-10-24 00:00 GMT

Overview

React hook providing Tauri window drag functionality via mouse events, with a cached window instance and a transparent drag region component.

Description

The useTauriDrag.jsx hook in src/ui/src/hooks/ lazily imports the Tauri getCurrentWindow API (cached via a module-level promise), then provides dragProps (spreadable props with onMouseDown handler that calls win.startDragging() on left-click), a DragRegion component (transparent overlay for drag areas), and startDrag (raw handler). Only active in Tauri desktop environments; no-ops in browser.

Usage

Import this hook in the app header or any element that should act as a window drag handle.

Code Reference

Source Location

Signature

export function useTauriDrag()
// Returns: { dragProps, DragRegion, startDrag }

Import

import { useTauriDrag } from './hooks/useTauriDrag';

I/O Contract

Inputs

Name Type Required Description
(none) — — No parameters

Outputs

Name Type Description
dragProps object { onMouseDown, style } to spread on any element
DragRegion Component Transparent div with drag handler
startDrag Function Raw drag start handler

Usage Examples

Drag Handle

import { useTauriDrag } from './hooks/useTauriDrag';

function AppHeader() {
  const { dragProps } = useTauriDrag();
  return <div {...dragProps} className="h-8 bg-gray-100">Drag here to move window</div>;
}

// Or transparent overlay
function App() {
  const { DragRegion } = useTauriDrag();
  return (
    <div>
      <DragRegion className="absolute top-0 left-0 right-0 h-8" />
      <MainContent />
    </div>
  );
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment