Vue.draggable: Change cursor while dragging

Created on 21 Feb 2020  路  4Comments  路  Source: SortableJS/Vue.Draggable

I want to change cursor while dragging the element. PLease help!!!!

Most helpful comment

For those who will end up here. I found those issues that helpt me

I finally manage to change the cursor while dragging by adding a class on the <html/>.
Here a simple example :

global.css

.grabbing * {
    cursor: grabbing !important;
}

myComponent.vue

<draggable
            draggable=".draggable"
            group="properties"
            filter=".ignore-draggable"
            :forceFallback="true"
            :preventOnFilter="false"
            @end="onDragEnd"
            @start="onStart"
        >
[...]
onDragEnd: function(e): void {
    const className = 'grabbing';
    const html = document.getElementsByTagName('html').item(0);
    if (html && new RegExp(className).test(html.className) === true) {
        // Remove className with the added space (from setClassToHTMLElement)
        html.className = html.className.replace(
            new RegExp(' ' + className),
            ''
        );
        // Remove className without added space (just in case)
        html.className = html.className.replace(new RegExp(className), '');
    }
}
onStart: function() {
    const className = 'grabbing';
    const html = document.getElementsByTagName('html').item(0);
    if (html && new RegExp(className).test(html.className) === false) {
        html.className += ' ' + className; // use a space in case there are other classNames
    }
}

All 4 comments

I want too !!! I figured out we cannot do it easily because of the css pointer-event: none set on the style of the sortable-chosen item... Anyone have a workaround ?

For those who will end up here. I found those issues that helpt me

I finally manage to change the cursor while dragging by adding a class on the <html/>.
Here a simple example :

global.css

.grabbing * {
    cursor: grabbing !important;
}

myComponent.vue

<draggable
            draggable=".draggable"
            group="properties"
            filter=".ignore-draggable"
            :forceFallback="true"
            :preventOnFilter="false"
            @end="onDragEnd"
            @start="onStart"
        >
[...]
onDragEnd: function(e): void {
    const className = 'grabbing';
    const html = document.getElementsByTagName('html').item(0);
    if (html && new RegExp(className).test(html.className) === true) {
        // Remove className with the added space (from setClassToHTMLElement)
        html.className = html.className.replace(
            new RegExp(' ' + className),
            ''
        );
        // Remove className without added space (just in case)
        html.className = html.className.replace(new RegExp(className), '');
    }
}
onStart: function() {
    const className = 'grabbing';
    const html = document.getElementsByTagName('html').item(0);
    if (html && new RegExp(className).test(html.className) === false) {
        html.className += ' ' + className; // use a space in case there are other classNames
    }
}

@sarahLardeau thanks for documenting your solution.

@sarahLardeau 3q锛実ood boy 銆傛杩庢潵鍥涘窛

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Laraveldeep picture Laraveldeep  路  3Comments

clemsontiger picture clemsontiger  路  3Comments

parthibeyond picture parthibeyond  路  3Comments

ghost picture ghost  路  3Comments

AlexandreBonneau picture AlexandreBonneau  路  3Comments