Open CoderK opened 2 years ago
i encountered same issues. I foudna solution to extends PointerSensor class directly and override activators
here my example
import { PointerSensor, PointerSensorOptions } from '@dnd-kit/core';
import type { PointerEvent } from 'react';
// override dnd kit pointer sensor to add key binder condition
// here original code https://github.com/clauderic/dnd-kit/blob/master/packages/core/src/sensors/pointer/PointerSensor.ts
export class CustomPointerSensor extends PointerSensor {
static activators = [
{
eventName: 'onPointerDown' as const,
handler: (
{ nativeEvent: event }: PointerEvent,
{ onActivation }: PointerSensorOptions,
): boolean => {
if (!event.isPrimary || event.button !== 0) {
return false;
}
// my override
if (event.altKey) return false;
onActivation?.({ event });
return true;
},
},
];
}
@Reykugo-Gear In my case, this code throws TypeError: Cannot read properties of undefined (reading 'activators'). Could you let me know if you managed to resolve it?
I'd like to extend AbstractPointerSensor to make a custom sensor.
But, in my project I cannot import AbstractPointerSensor class. That's because AbstractPointerSensor is not being exported.
https://github.com/clauderic/dnd-kit/blob/master/packages/core/src/index.ts
So I made a detour like this,
Modifying static member doesn't seem to be a good way. This error occurs.
I can solve it if you can export AbstractPointerSensor, is there any other good way to solve this problem?