NativeDesktopTitleBar component provides a fully customizable, draggable title bar designed for Electron-based Native Desktop applications. It allows developers to replace the default OS title bar with a custom React-driven UI, giving full control over layout, styling, and interactivity.
Overview
NativeDesktopTitleBar is a React component that renders a flexible container at the top of the application window. It supports custom alignment, dynamic visibility, and drag regions that integrate with Electron’s window controls (e.g., drag, maximize, unmaximize). It does not rely on any external CSS files, all styles are inline and customizable via props.
Key Features
- Draggable region support using
WebkitAppRegionfor Electron windows. - Fully customizable layout via
contentAlignment, padding, height, and inline styles. - Composable components array, render any React elements (buttons, titles, icons, menus, etc.) inside the title bar.
- Visibility control for both the entire title bar and individual components.
- Double-click maximize/unmaximize behavior, mimicking native window behavior.
Usage Example
Titlebar Component
Props
Component Types
Each component object inside thecomponents array defines what to render and how it behaves.
Content Alignment Options
ThecontentAlignment prop controls horizontal positioning of child components.
Notes
- The title bar is rendered as a fixed element positioned at the top of the viewport.
- The container has a default background color of red — intended for debugging. You should override it using the
styleprop. - For best results, combine with Electron’s frameless window mode.
Developer Notes
Design Philosophy
- The component is style-agnostic, no CSS or theme dependency.
- Built for Electron environments only, where frameless windows require custom drag and control logic.
- Uses flexbox layout for predictable alignment and composability.
Drag Region Behavior
- Setting
WebkitAppRegion: dragmakes an area draggable by Native Desktop. - MacOS and Windows handle drag regions slightly differently:
- On macOS, buttons near the top-left may interfere with draggable areas; ensure custom buttons are within
no-dragzones. - On Windows, draggable areas may overlap invisible hitboxes if padding or overlapping elements are misaligned.
- On macOS, buttons near the top-left may interfere with draggable areas; ensure custom buttons are within
Always mark interactive elements (buttons, menus) as
isDragable: false.Window Events
- Double-clicking toggles maximize/unmaximize via
window.nativeDesktopWindow. - Developers can disable this behavior by removing or replacing the event listener.
Performance & Rendering
- The component uses inline styles to avoid runtime stylesheet loading.
- Recommended for small, lightweight render trees (<10 child components).
- Since it’s fixed-positioned, it won’t reflow with other layout changes.
Accessibility
- The component itself doesn’t handle focus, keyboard navigation, or ARIA roles yet.
- If accessibility is a priority, wrap internal components (like buttons or menus) with proper roles and keyboard handlers.