fix table context menu/drag-select

Summary:
As seen [here](https://fb.workplace.com/groups/230455004101832/permalink/623364598144202/?comment_id=623436418137020&comment_tracking=%7B%22tn%22%3A%22R%22%7D) using the primary key + CTRL to open the context menu, triggers the drag-select mode. This should not be the case. This diff changes the behaviour to:

- Not trigger the drag-select-mode, when openting the context menu using CTRL
- Select the current row, when performing a context click on it.

Reviewed By: jknoxville

Differential Revision: D15538057

fbshipit-source-id: d3d086c3d44618b2801e3a9b0646689c04fa32ff
This commit is contained in:
Daniel Büchele
2019-05-30 02:32:13 -07:00
committed by Facebook Github Bot
parent c94c2c8455
commit 8c4e373dfc

View File

@@ -372,11 +372,6 @@ class ManagedTable extends React.Component<
row: TableBodyRow,
index: number,
) => {
if (e.button !== 0 || !this.props.highlightableRows) {
// Only highlight rows when using primary mouse button,
// otherwise do nothing, to not interfere context menus.
return;
}
if (e.shiftKey) {
// prevents text selection
e.preventDefault();
@@ -384,11 +379,18 @@ class ManagedTable extends React.Component<
let {highlightedRows} = this.state;
this.dragStartIndex = index;
document.addEventListener('mouseup', this.onStopDragSelecting);
const contextClick =
e.button !== 0 ||
(process.platform === 'darwin' && e.button === 0 && e.ctrlKey);
if (!contextClick) {
this.dragStartIndex = index;
document.addEventListener('mouseup', this.onStopDragSelecting);
}
if (
((e.metaKey && process.platform === 'darwin') || e.ctrlKey) &&
((process.platform === 'darwin' && e.metaKey) ||
(process.platform !== 'darwin' && e.ctrlKey)) &&
this.props.multiHighlight
) {
highlightedRows.add(row.key);