-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handling of mouse events in the table body. (#427)
Previously, mouse events in the table body were used for selecting regions. With the addition of interactive cells such as `EditableCell` components, we must now provide full mouse interativity to parts of the table body. Previously, two instances of `Draggable` were contending for mouse events. The first was waiting for double clicks to focus the `EditableCell`. The second was listening for clicks and drags for region selection. Both of these were invoking `preventDefault`, which was preventing text selection from working withing the `EditableCell` even when it was in edit mode. This change adds new props to `Draggable` to control the use of `preventDefault` and `stopPropagation` on the mouse events. We also added an `iteractive` prop to the `Cell` component, which applies a z-index that brings the cell above the region layer. Now, the table body will listen for clicks and drags for selection. `EditableCell`s will listen for double clicks to start editing. When editing is begun, the cell become "interative" and it is moved to a z-index above the selection regions layer. Also during edit mode, the `preventDefault` prop is disabled and `stopPropagation` is enabled to prevent the table body from messing with selected regions. This prevents an issue where the user starts dragging a text selection in an `EditableCell` and ends up selecting regions. In addition, we performed some cleanup on the table body: Consolidated ghost and non-ghost render methods, which were nearly identical. Moved selection interaction component to top-level of table body instead of attaching listeners to individual cells. This will reduce the total number of event listeners attached to DOM elements. However, it did necessitate the creation of a small wrapper to use the `ContextMenuTarget` decorator.
- Loading branch information
1 parent
899f564
commit fc0e8d4
Showing
13 changed files
with
240 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
* Licensed under the BSD-3 License as modified (the “License”); you may obtain a copy | ||
* of the license at https://github.com/palantir/blueprint/blob/master/LICENSE | ||
* and https://github.com/palantir/blueprint/blob/master/PATENTS | ||
*/ | ||
|
||
import { ContextMenuTarget, IProps } from "@blueprintjs/core"; | ||
import * as React from "react"; | ||
|
||
export interface IContextMenuTargetWrapper extends IProps { | ||
renderContextMenu: (e: React.MouseEvent<HTMLElement>) => JSX.Element; | ||
style: React.CSSProperties; | ||
} | ||
|
||
/** | ||
* Since the ContextMenuTarget uses the `onContextMenu` prop instead | ||
* `element.addEventListener`, the prop can be lost. This wrapper helps us | ||
* maintain context menu fuctionality when doing fancy React.cloneElement | ||
* chains. | ||
*/ | ||
@ContextMenuTarget | ||
export class ContextMenuTargetWrapper extends React.Component<IContextMenuTargetWrapper, {}> { | ||
public render() { | ||
const { className, children, style } = this.props; | ||
return <div className={className} style={style}>{children}</div>; | ||
} | ||
|
||
public renderContextMenu(e: React.MouseEvent<HTMLElement>) { | ||
return this.props.renderContextMenu(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
fc0e8d4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better handling of mouse events in the table body. (#427)
Preview: docs
Coverage: core | datetime