react-data-grid icon indicating copy to clipboard operation
react-data-grid copied to clipboard

Context Menu long mouse press trigger context menu

Open pgdesjardins opened this issue 6 years ago • 4 comments

  • Have you already searched for similar issues? Please help us out and double-check first!

  • Also, please don't be that person who deletes this template. It's here for a reason.

  • Thanks!


Which version of React JS are you using?

version

  • [ x] v6.0.1
  • [ x] v5.0.4

Which browser are you using?

✅ Officially supported ✅

  • [x] Chrome

I'm submitting a ...

  • [x ] 🐛 Bug Report
  • [ ] 💡 Feature Request

Issue Details

Long mouse click (primary button) triggers context menu. If a cell was selected and you execute the long press on an other row cell, the context menu displayed is bound yo the selected cell, not the cell where you are clicking

- What the current behavior is
long press (around 2 seconds) of primary button opens context menu
- What the desired behavior is
it should not do that

You can recreate this on the current example code at https://adazzle.github.io/react-data-grid/docs/examples/context-menu

recording of the behavior
https://youtu.be/3iCiI4TO_h8

pgdesjardins avatar Feb 06 '20 21:02 pgdesjardins

Hello, you can disable this behavior by changing the 'holdToDisplay' (as -1) property from the set ContextMenuTrigger. You can find the description here: https://github.com/vkbansal/react-contextmenu/blob/master/docs/api.md

apo5tol avatar Feb 12 '20 15:02 apo5tol

@apo5tol I'm interested in these features too. Could you show me how can I do that? I have access to "ContextMenuTrigger" only via: RowsContainer={ContextMenuTrigger} as shown in the examples. Is there a way like... RowsContainer={<ContextMenuTrigger />} ?

emsi-iggy avatar Feb 20 '20 20:02 emsi-iggy

@emsi-iggy For example:

import React, { useState } from "react";
import ReactDOM from "react-dom";
import ReactDataGrid from "react-data-grid";
import { Menu } from "react-data-grid-addons";
const { Row } = ReactDataGrid;
const { ContextMenu, MenuItem, ContextMenuTrigger } = Menu;

const defaultColumnProperties = {
  sortable: true,
  width: 120
};

const rows = [
  { id: 1, name: "row 1" },
  { id: 2, name: "row 2" },
  { id: 3, name: "row 3" }
];

const columns = [
  {
    key: "id",
    name: "ID"
  },
  {
    key: "name",
    name: "Name"
  }
].map(c => ({ ...c, ...defaultColumnProperties }));

function ExampleContextMenu({ idx, id, rowIdx }) {
  return (
    <ContextMenu id={"grid-contexmenu"}>
      <MenuItem data={{ rowIdx, idx }}>Menu item 1</MenuItem>
      <MenuItem data={{ rowIdx, idx }}>Menu item 2</MenuItem>
    </ContextMenu>
  );
}

const RowRenderer = function(props) {
  return (
    <ContextMenuTrigger id={"grid-contexmenu"} holdToDisplay={-1}>
      <Row {...props} />
    </ContextMenuTrigger>
  );
};

function Example({ initialRows }) {
  const [rows, setRows] = useState(initialRows);

  return (
    <ReactDataGrid
      columns={columns}
      rowGetter={i => rows[i]}
      rowsCount={rows.length}
      minHeight={500}
      rowRenderer={RowRenderer}
      contextMenu={<ExampleContextMenu />}
    />
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<Example initialRows={rows} />, rootElement);

apo5tol avatar Feb 21 '20 08:02 apo5tol

contextMenu prop will be removed in v7 but it is still possible to add a context menu. This was done so users can customize the behavior. Please take a look at the following example

https://adazzle.github.io/react-data-grid/canary/?path=/story/demos--context-menu https://github.com/adazzle/react-data-grid/blob/canary/stories/demos/ContextMenu.tsx https://github.com/adazzle/react-data-grid/blob/canary/CHANGELOG.md

amanmahajan7 avatar Apr 29 '20 02:04 amanmahajan7