Repository navigation
Conversation
|
@kachurun is attempting to deploy a commit to the CopilotKit Team on Vercel. A member of the Team first needs to authorize it. |
| const minGapFromEdge = 60; | ||
| const verticalOffsetFromCorner = 35; | ||
| const horizontalOffsetFromCorner = 15; | ||
| let top = rect.top + window.scrollY - el.offsetHeight + verticalOffsetFromCorner; |
There was a problem hiding this comment.
el.offsetHeight here doesn't make any sense because it renders as an empty div, so its height will be equal to 1em by default (just block paddings). Also, it's weird to position it 35px from the top side of the selection. It must use the bottom if we're trying to position the modal below the selection.
| if (top < minGapFromEdge) { | ||
| top = rect.bottom + window.scrollY + minGapFromEdge; |
There was a problem hiding this comment.
This case is possible only in a crazy scenario when the textarea is positioned above the start of the document. I don't think it's worth caring about this case. Fix me if I'm wrong and I rewrite it like let top = Math.max(verticalOffsetFromCorner, rect.bottom + window.scrollY + verticalOffsetFromCorner);
| const minGapFromEdge = 60; | ||
| const verticalOffsetFromCorner = 35; | ||
| const horizontalOffsetFromCorner = 15; |
There was a problem hiding this comment.
Magic numbers are uncontrolled by the user. And what is "edge" and what is "corner" is pretty unclear. I reset it but left the variables to make future improvements easier.
|
|
||
| el.style.top = `${top}px`; | ||
| el.style.left = `${left}px`; | ||
| }); |
There was a problem hiding this comment.
There's no reason to recalculate it on every selection change (e.g., input in the textarea).
| editorState: EditingEditorState; | ||
| apiConfig: InsertionEditorApiConfig; | ||
| performInsertion: (insertedText: string) => void; | ||
| closeWindow: () => void; |
There was a problem hiding this comment.
This thing isn't used anywhere.
| if (!isShown) { | ||
| return null; | ||
| } |
There was a problem hiding this comment.
No need to portal an empty <Menu> until we need to show the modal.
ea3626a to
fc83c68
Compare
⏭️ Changeset Not RequiredLatest commit: fc83c68 No changes in this PR affected the Changeset is not required for this PR. |
|
@kachurun Thanks for opening this. If you are, let's do all the changes, if you prefer multiple PRs, we can do that as well. We have not seen many instances of textarea component being used and hece it was not touched in long time. We would be more than happy to take this contribution. :) |
|
@suhasdeshpande Cool, I’ll make the next changes, but maybe not within the textarea component. So, for now, I think we should merge this PR to fix current minor issue and not expect all these changes in the upcoming commits to this one. |
|
This has been merged as apart of this PR #1868, thank you! |
What does this PR do?
This PR primarily fixes the issue where the react-textarea component was injecting an unnecessary div into the body.
It also addresses several bugs related to window positioning — the position was being calculated before the content inside the window was rendered, which in some cases caused the window to overlap the content.
This PR can be merged, but I don’t consider the work complete — in my opinion, the component needs a full rewrite.
Here are the main issues still in the code and/or logic:
HoveringToolbar is bundled into react-textarea by default
It shouldn’t be. I expect to control this behavior myself and insert the HoveringToolbar wherever I need it. For example, I might want to render a button inside the input that triggers the window, or even trigger the UI with a hotkey from anywhere in the app — not just when a textarea is focused.
No proper positioning logic
The window lacks flexibility in how it’s positioned. I generally avoid extra dependencies, but in this case, Floating UI would be very helpful. For example, Radix UI uses it under the hood.
Magic numbers in the code
Take verticalOffsetFromCorner, for example — it’s not configurable and doesn’t really make sense, so I just zeroed it out. You can achieve the same effect using padding on the root element (which already has 0.5em on all sides).
Breaks in complex layouts
The window cannot position itself properly if it’s rendered inside an iframe or if the target element lives inside a custom scroll container.
And that’s not even the full list. Fixing all of this will require a serious rewrite, which would be a breaking change.
I’d be happy to take that on if I get the green light.