Skip to content

Commit b08a9fd

Browse files
committed
Refactor drag event handling to support multiple input containers in chat widget
1 parent 6b35ca9 commit b08a9fd

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

packages/jupyter-chat/src/widgets/chat-widget.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,19 @@ export class ChatWidget extends ReactWidget {
122122
* Handle drag over events
123123
*/
124124
private _handleDrag(event: Drag.Event): void {
125-
const inputContainer = this.node.querySelector(`.${INPUT_CONTAINER_CLASS}`);
125+
const inputContainers = this.node.querySelectorAll<HTMLElement>(
126+
`.${INPUT_CONTAINER_CLASS}`
127+
);
126128
const target = event.target as HTMLElement;
127-
const isOverInput =
128-
inputContainer?.contains(target) || inputContainer === target;
129+
let overInput: HTMLElement | null = null;
130+
for (const container of inputContainers) {
131+
if (container.contains(target)) {
132+
overInput = container;
133+
break;
134+
}
135+
}
129136

130-
if (!isOverInput) {
137+
if (!overInput) {
131138
this._removeDragHoverClass();
132139
return;
133140
}
@@ -140,12 +147,9 @@ export class ChatWidget extends ReactWidget {
140147
event.stopPropagation();
141148
event.dropAction = 'move';
142149

143-
if (
144-
inputContainer &&
145-
!inputContainer.classList.contains(DRAG_HOVER_CLASS)
146-
) {
147-
inputContainer.classList.add(DRAG_HOVER_CLASS);
148-
this._dragTarget = inputContainer as HTMLElement;
150+
if (!overInput.classList.contains(DRAG_HOVER_CLASS)) {
151+
overInput.classList.add(DRAG_HOVER_CLASS);
152+
this._dragTarget = overInput;
149153
}
150154
}
151155

0 commit comments

Comments
 (0)