Documentation / Feedback & overlays
Detachable
Detaches a piece of interface into a separate browser window (window.open + createPortal): a player, a dashboard or notes you want to keep on a second screen. The children stay in the page’s React tree: they keep their state, their context and their handlers; only their rendering moves to another window. While detached, nothing is rendered in their original place. What they open opens in their window: the list of a Select, the menu of a Dropdown, a Modal or a Drawer.
The page’s stylesheets are copied into the window (copyStyles, on by default), then tracked if new ones appear. The user closing the window is detected and reported through onClose. The component is controlled (detached) or uncontrolled (defaultDetached and the detach() / attach() ref). To sync a value between windows or to clone instead of moving, see AdvanceDetachable. A "use client" component.
Examples
Controlled mode
detached opens the window; onClose sets the state back to false when the user closes it.
import { useState } from "react";
import { Button, Detachable } from "@synertech/ui";
export function Controlled() {
const [detached, setDetached] = useState(false);
return (
<div className="space-y-3">
<Button onClick={() => setDetached((value) => !value)}>
{detached ? "Rattacher" : "Détacher"}
</Button>
<Detachable
detached={detached}
onClose={() => setDetached(false)}
title="Notes de réunion"
width={480}
height={360}
>
<div className="rounded-lg border border-gray-200 p-4">
<h3 className="font-semibold">Notes de réunion</h3>
<p className="text-sm text-gray-600">Ce bloc peut vivre dans sa propre fenêtre.</p>
</div>
</Detachable>
</div>
);
}Driving it through a ref
Without detached, the ref exposes detach(), attach(), isDetached and the open window.
import { useRef } from "react";
import { Button, Detachable, type DetachableRef } from "@synertech/ui";
export function WithRef() {
const ref = useRef<DetachableRef>(null);
return (
<div className="space-y-3">
<div className="flex gap-2">
<Button size="sm" onClick={() => ref.current?.detach()}>
Ouvrir à part
</Button>
<Button size="sm" onClick={() => ref.current?.attach()}>
Rattacher
</Button>
</div>
<Detachable ref={ref} title="Chronomètre" onDetach={() => console.log("Fenêtre ouverte")}>
<p className="text-3xl font-mono">00:42</p>
</Detachable>
</div>
);
}Blocked popup and positioning
onPopupBlocked warns when the browser refuses to open the window; left / top place the window instead of centring it.
import { useState } from "react";
import { Button, Detachable } from "@synertech/ui";
export function PopupBlocked() {
const [detached, setDetached] = useState(false);
const [blocked, setBlocked] = useState(false);
return (
<div className="space-y-3">
<Button
onClick={() => {
setBlocked(false);
setDetached(true);
}}
>
Ouvrir le tableau de bord
</Button>
{blocked && (
<p className="text-sm text-red-600">Autorisez les fenêtres surgissantes pour ce site.</p>
)}
<Detachable
detached={detached}
left={40}
top={40}
onClose={() => setDetached(false)}
onPopupBlocked={() => {
setBlocked(true);
setDetached(false);
}}
>
<p className="p-4">Indicateurs du jour</p>
</Detachable>
</div>
);
}API reference
Components
import { Detachable } from "@synertech/ui";Props — DetachableProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
center |
boolean |
true |
|
className |
string |
— | |
closeOnParentUnmount |
boolean |
true |
|
copyStyles |
boolean |
true |
|
defaultDetached |
boolean |
false |
|
detached |
boolean |
— | |
height |
number |
600 |
|
left |
number |
— | |
onClose |
() => void |
— | |
onDetach |
() => void |
— | |
onPopupBlocked |
() => void |
— | The browser refused to open the window (a popup blocker: expected with |
title |
string |
"" |
|
top |
number |
— | |
width |
number |
800 |
|
windowClassName |
string |
— |
+ 2 inherited native attributes from RefAttributes, Attributes (className, id, aria-*, event handlers…).
Types
DetachableRef
Interfaceinterface DetachableRef| Field | Type | Default | Description |
|---|---|---|---|
attach• |
() => void |
— | |
detach• |
() => void |
— | |
isDetached• |
boolean |
— | |
window• |
Window | null |
— |