Skip to content

Commit

Permalink
Add tab/enter nav while editing, address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gscshoyru committed Oct 19, 2017
1 parent 5eb55fe commit 8fa7b3c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
14 changes: 3 additions & 11 deletions packages/table/src/cell/cell.tsx
Expand Up @@ -71,12 +71,12 @@ export interface ICellProps extends IIntentProps, IProps {
tabIndex?: number;

/**
* Callback to be called when cell is focused and key is pressed down.
* Callback to be called when the cell is focused and a key is pressed down.
*/
onKeyDown?: React.KeyboardEventHandler<HTMLElement>;

/**
* Callback to be called when cell is focused and key is released.
* Callback to be called when the cell is focused and a key is released.
*/
onKeyUp?: React.KeyboardEventHandler<HTMLElement>;

Expand Down Expand Up @@ -165,15 +165,7 @@ export class Cell extends React.Component<ICellProps, {}> {
const content = <div className={textClasses}>{modifiedChildren}</div>;

return (
<div
className={classes}
style={style}
title={tooltip}
tabIndex={tabIndex}
onKeyDown={onKeyDown}
onKeyUp={onKeyUp}
ref={cellRef}
>
<div className={classes} title={tooltip} ref={cellRef} {...{ style, tabIndex, onKeyDown, onKeyUp }}>
<LoadableContent loading={loading} variableLength={true}>
{content}
</LoadableContent>
Expand Down
15 changes: 8 additions & 7 deletions packages/table/src/cell/editableCell.tsx
Expand Up @@ -16,7 +16,7 @@ import { Cell, ICellProps } from "./cell";

export interface IEditableCellProps extends ICellProps {
/**
* Whether or not the given cell is the current active/focused cell.
* Whether the given cell is the current active/focused cell.
*/
isFocused?: boolean;

Expand Down Expand Up @@ -66,6 +66,11 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
};

private cellRef: HTMLElement;
private refHandlers = {
cell: (ref: HTMLElement) => {
this.cellRef = ref;
},
};

public constructor(props: IEditableCellProps, context?: any) {
super(props, context);
Expand Down Expand Up @@ -131,7 +136,7 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
}

return (
<Cell {...spreadableProps} truncated={false} interactive={interactive} cellRef={this.handleCellRef}>
<Cell {...spreadableProps} truncated={false} interactive={interactive} cellRef={this.refHandlers.cell}>
<Draggable
onActivate={this.handleCellActivate}
onDoubleClick={this.handleCellDoubleClick}
Expand All @@ -149,7 +154,7 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
<Hotkeys>
<Hotkey
key="edit-cell"
label="Edit the currely focused cell"
label="Edit the currently focused cell"
group="Table"
combo="f2"
onKeyDown={this.handleEdit}
Expand All @@ -165,10 +170,6 @@ export class EditableCell extends React.Component<IEditableCellProps, IEditableC
}
}

private handleCellRef = (cellRef: HTMLElement) => {
this.cellRef = cellRef;
};

private handleEdit = () => {
this.setState({ isEditing: true, dirtyValue: this.state.savedValue });
};
Expand Down
4 changes: 4 additions & 0 deletions packages/table/src/table.tsx
Expand Up @@ -988,27 +988,31 @@ export class Table extends AbstractComponent<ITableProps, ITableState> {
group="Table"
combo="tab"
onKeyDown={this.handleFocusMoveRightInternal}
allowInInput={true}
/>,
<Hotkey
key="move shift-tab"
label="Move focus cell shift tab"
group="Table"
combo="shift+tab"
onKeyDown={this.handleFocusMoveLeftInternal}
allowInInput={true}
/>,
<Hotkey
key="move enter"
label="Move focus cell enter"
group="Table"
combo="enter"
onKeyDown={this.handleFocusMoveDownInternal}
allowInInput={true}
/>,
<Hotkey
key="move shift-enter"
label="Move focus cell shift enter"
group="Table"
combo="shift+enter"
onKeyDown={this.handleFocusMoveUpInternal}
allowInInput={true}
/>,
];
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/table/src/tableBodyCells.tsx
Expand Up @@ -25,7 +25,7 @@ export interface ITableBodyCellsProps extends IRowIndices, IColumnIndices, IProp
cellRenderer: ICellRenderer;

/**
* The location of the focused cell, for setting the "focused" property on cells
* The coordinates of the currently focused cell, for setting the "isFocused" prop on cells.
*/
focusedCell?: IFocusedCellCoordinates;

Expand Down

0 comments on commit 8fa7b3c

Please sign in to comment.