Skip to content

Commit 9140b03

Browse files
authored
Merge pull request #350 from haydenbleasel/main
2 parents 9008395 + d04495a commit 9140b03

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

apps/docs/guides/tailwind/setup.mdx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ description: "Follow this guide to set up Novel with Tailwindcss"
1414
href="https://ui.shadcn.com/docs/installation"
1515
>
1616
You can find more info about installing shadcn-ui here. You will need to add
17-
the following components: <b>Button, Separator, Popover, Command, Dialog,</b>
17+
the following components: <b>Button, Separator, Popover, Command, Dialog</b>
1818
</Card>
1919

2020
This example will use the same stucture from here: [Anatomy](/quickstart#anatomy)\
@@ -339,3 +339,7 @@ import { defaultEditorProps, EditorContent } from "novel";
339339
</AccordionGroup>
340340

341341
<Note>You need `require("@tailwindcss/typography")` for the prose styling</Note>
342+
343+
## Usage within Dialogs
344+
345+
Novel has been designed to work automatically within Radix Dialogs, namely by looking for the closest parent attribute `[role="dialog"]`. If you're using a different implementation for popups and dialogs, ensure you add this attribute above the editor so the drag handle calculates the correct position.

packages/headless/src/extensions/drag-and-drop.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ export interface DragHandleOptions {
1212
}
1313
function absoluteRect(node: Element) {
1414
const data = node.getBoundingClientRect();
15+
const modal = node.closest('[role="dialog"]');
16+
17+
if (modal && window.getComputedStyle(modal).transform !== "none") {
18+
const modalRect = modal.getBoundingClientRect();
19+
20+
return {
21+
top: data.top - modalRect.top,
22+
left: data.left - modalRect.left,
23+
width: data.width,
24+
};
25+
}
1526

1627
return {
1728
top: data.top,
@@ -154,7 +165,7 @@ function DragHandle(options: DragHandleOptions) {
154165
y: event.clientY,
155166
});
156167

157-
if (!(node instanceof Element)) {
168+
if (!(node instanceof Element) || node.matches("ul, ol")) {
158169
hideDragHandle();
159170
return;
160171
}

0 commit comments

Comments
 (0)