-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DataTable: 10.8.3 - Drag selection fails due to TypeError: event.originalEvent is undefined
(Next.JS)
#7200
Comments
event.originalEvent
is undefined (Next.JS)event.originalEvent is undefined
(Next.JS)
event.originalEvent is undefined
(Next.JS)TypeError: event.originalEvent is undefined
(Next.JS)
@melloware I got the same problem so it's not NextJs related. I've analysed that a few min and figured out, that if you start in the upper left corner and drag down/right - that error seems not to happen. In that case var _onMouseDown = function onMouseDown(event) {
props.onRowMouseDown({
originalEvent: event,
data: props.rowData,
index: props.rowIndex
});
}; is called. However - if you start with one of the other corners and try to drag select not just the var _onDragStart = function onDragStart(event) {
props.onRowDragStart({
originalEvent: event,
data: props.rowData,
index: props.rowIndex
});
}; also. The problem here is the implementation of var onRowDragStart = function onRowDragStart(e) {
var event = e.originalEvent,
index = e.index;
if (allowRowDrag(event)) after the var allowDrag = function allowDrag(event) {
return props.dragSelection && isMultipleSelection() && !event.originalEvent.shiftKey;
}; because event.originalEvent isn't defined. |
basically it needs |
That would avoid the error at this point, yes. However I'm not sure if thats the right place - just because we would avoid that doesn't mean we fixed it. The question here is "Why is dragStart called in 3 of 4 cases" i guess |
Good question! |
hey @sja-cslab @SolidAnonDev @melloware check PR #7217 -》 The main issue is the existing implementation of changing the function const allowRowDrag = (event) => {
return (!allowCellSelection() && allowDrag(event)) || props.reorderableRows;
}; to the following const allowRowDrag = (event) => {
return (!allowCellSelection() && allowDrag({ originalEvent: event })) || props.reorderableRows;
}; Fixes the issue |
@gcko are you pretty sure? While debugging i noticed, that originalEvent is already there at least in some cases. And that seems to be the problem. As said before, the problem is caused by the destructuring here: var onRowDragStart = function onRowDragStart(e) {
var event = e.originalEvent, // this here is bad for following code
index = e.index;
if (allowRowDrag(event)) { // previous desctucture make callchain within here throw But - and that's what i asked @melloware before is the question, why dragStart is called sometimes. You can currently start dragselection in top/left and move your mouse down/right - that makes onDragStart not get called. Or is there something I don't see? |
@sja-cslab 🤔 you are right, my "fix" is incorrect, let me look again |
Don't restructure `originalEvent` in `allowRowDrag`, just pass the full event through from `onRowDragStart`
Alright @sja-cslab, I removed the change and instead bypass the destructing by passing Regarding The
It seems like there is a relationship between if (allowRowDrag(e)) {
enableDragSelection(event, 'row');
anchorRowIndex.current = e.index;
rangeRowIndex.current = e.index;
anchorRowFirst.current = props.first;
} The
|
@gcko guess you are absolutely right. What I don't get is why the drag event is called based on mouse move direction (if thats even the trigger). But that should be analysed in another ticket... |
We just got #7221 bet that is related somehow. Edit: I just looked around in last merged PRs and found this one. Not sure if that's the reason for that but the changed |
@KumJungMin can you look at what @sja-cslab is saying |
@sja-cslab agreed #7221 is related to this issue (and should be fixed by my pr as well) regarding the diff from the PR you referenced, #7051, That logic makes the Typescript dev in me cringe, however lets break down the change: // isDraggableHandle can be either a boolean or an HTMLElement or null
const isDraggableHandle = isUnstyled()
// returns boolean | HTMLElement | null
? DomHandler.getAttribute(event.target, 'data-pc-section') === 'rowreordericon' || event.target.closest('[data-pc-section="rowreordericon"]')
// returns boolean | HTMLElement | null
: DomHandler.hasClass(event.target, 'p-datatable-reorderablerow-handle') || event.target.closest('.p-datatable-reorderablerow-handle');
// can be one of boolean | HTMLElement | null
event.currentTarget.draggable = isDraggableHandle;
// can be a boolean (using `!` will coalesce a value to a boolean)
event.target.draggable = !isDraggableHandle; As you said @sja-cslab, the logic is different. Also because of the coalescing the values can be wrong for // use !! to force it to a boolean
event.currentTarget.draggable = !!isDraggableHandle; Extra info on the |
Describe the bug
Drag selection fails and is in general having problems across version 10.8.2 and 10.8.3, but appears to be entirely broken in 10.8.3 in Next.JS
See #7192 for previous bug report regarding 10.8.2
Reproducer
https://stackblitz.com/edit/stackblitz-starters-zx3txq?file=package.json
System Information
Steps to reproduce the behavior
Expected behavior
A successful drag selection can be made.
The text was updated successfully, but these errors were encountered: