Implementation:0xranx OpenContext useTauriDrag
| 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
- Repository: 0xranx_OpenContext
- File: src/ui/src/hooks/useTauriDrag.jsx
- Lines: 1-93
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>
);
}