Skip to content
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

Grab cursor while dragging item #2930

Open
RajaThomas opened this issue Dec 23, 2020 · 1 comment
Open

Grab cursor while dragging item #2930

RajaThomas opened this issue Dec 23, 2020 · 1 comment

Comments

@RajaThomas
Copy link

RajaThomas commented Dec 23, 2020

have an HTML page which has some draggable elements. Our specs say that hovering mouse on such element the cursor must be grab, and during drag cursor must be grabbing..

So the question is: What am I missing to show grabbing cursor (grabbing) during drag?

import React, { Component } from 'react';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { DndProvider } from 'react-dnd';
import withScrolling from 'react-dnd-scrolling';
import DragItem from './DragItem';
import './App.css';

const ScrollingComponent = withScrolling('div');

const ITEMS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

export default class App extends Component {
  render() {
    return (
      <DndProvider backend={HTML5Backend}>
        <ScrollingComponent className="App">
          {ITEMS.map(n => (
            <DragItem key={n} label={`Item ${n}`} />
          ))}
        </ScrollingComponent>
      </DndProvider>
    );
  }
}
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import { DragSource } from 'react-dnd';
import './DragItem.css';

class DragItem extends PureComponent {
  static propTypes = {
    label: PropTypes.string.isRequired
  };

  render() {
    return this.props.dragSource(<div className="DragItem">{this.props.label}</div>);
  }
}

export default DragSource(
  'foo',
  {
    beginDrag() {
      document.body.classList.add('dragging');
      return {};
    }
  },
  connect => ({
    dragSource: connect.dragSource()
  })
)(DragItem);

.dragging {
  cursor: grabbing;
  cursor: -moz-grabbing;
  cursor: -webkit-grabbing;
}

while im begin the dragging im manually adding the css class document.body.classList.add('dragging'); for grabbing feature

@samcw
Copy link

samcw commented Jul 5, 2021

#325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants