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

[Table/EditableCell] Type in a cell to edit it now #1760

Merged
merged 3 commits into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/table/src/cell/cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ export interface ICellProps extends IIntentProps, IProps {
*/
onKeyUp?: React.KeyboardEventHandler<HTMLElement>;

/**
* Callback invoked when a character-key is pressed.
*/
onKeyPress?: React.KeyboardEventHandler<HTMLElement>;

/**
* A ref handle to capture the outer div of this cell. Used internally.
*/
Expand Down Expand Up @@ -108,6 +113,7 @@ export class Cell extends React.Component<ICellProps, {}> {
tabIndex,
onKeyDown,
onKeyUp,
onKeyPress,
style,
intent,
interactive,
Expand Down Expand Up @@ -163,7 +169,12 @@ export class Cell extends React.Component<ICellProps, {}> {
const content = <div className={textClasses}>{modifiedChildren}</div>;

return (
<div className={classes} title={tooltip} ref={cellRef} {...{ style, tabIndex, onKeyDown, onKeyUp }}>
<div
className={classes}
title={tooltip}
ref={cellRef}
{...{ style, tabIndex, onKeyDown, onKeyUp, onKeyPress }}
>
<LoadableContent loading={loading} variableLength={true}>
{content}
</LoadableContent>
Expand Down
18 changes: 16 additions & 2 deletions packages/table/src/cell/editableCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
onConfirm={this.handleConfirm}
onEdit={this.handleEdit}
placeholder=""
selectAllOnFocus={true}
selectAllOnFocus={false}
value={dirtyValue}
/>
);
Expand All @@ -134,7 +134,13 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
}

return (
<Cell {...spreadableProps} truncated={false} interactive={interactive} cellRef={this.refHandlers.cell}>
<Cell
{...spreadableProps}
truncated={false}
interactive={interactive}
cellRef={this.refHandlers.cell}
onKeyPress={this.handleKeyPress}
>
<Draggable
onActivate={this.handleCellActivate}
onDoubleClick={this.handleCellDoubleClick}
Expand Down Expand Up @@ -168,6 +174,14 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
}
}

private handleKeyPress = () => {
if (this.state.isEditing || !this.props.isFocused) {
return;
}
// setting dirty value to empty string because apparently the text field will pick up the key and write it in there
this.setState({ isEditing: true, dirtyValue: "", savedValue: this.state.savedValue });
};

private handleEdit = () => {
this.setState({ isEditing: true, dirtyValue: this.state.savedValue });
};
Expand Down