Skip to content

Commit a6e1d83

Browse files
press enter will expand cell
1 parent f604913 commit a6e1d83

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Cell.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ const Cell = React.createClass({
9898
}
9999
},
100100

101+
onCellKeyDown(e) {
102+
if (this.canExpand() && e.key === 'Enter') {
103+
this.onCellExpand(e);
104+
}
105+
},
106+
101107
onDragHandleDoubleClick(e) {
102108
e.stopPropagation();
103109
let meta = this.props.cellMetaData;
@@ -120,7 +126,7 @@ const Cell = React.createClass({
120126
return style;
121127
},
122128

123-
getFormatter(): ?ReactElement {
129+
getFormatter() {
124130
let col = this.props.column;
125131
if (this.isActive()) {
126132
return <EditorContainer rowData={this.getRowData()} rowIdx={this.props.rowIdx} idx={this.props.idx} cellMetaData={this.props.cellMetaData} column={col} height={this.props.height}/>;
@@ -327,6 +333,10 @@ const Cell = React.createClass({
327333
return (this.props.column.editor != null) || this.props.column.editable;
328334
},
329335

336+
canExpand() {
337+
return this.props.expandableOptions && this.props.expandableOptions.canExpand;
338+
},
339+
330340
renderCellContent(props) {
331341
let CellContent;
332342
let Formatter = this.getFormatter();
@@ -341,8 +351,8 @@ const Cell = React.createClass({
341351
let cellExpander;
342352
let marginLeft = this.props.expandableOptions ? (this.props.expandableOptions.treeDepth * 30) : 0;
343353
let marginLeftCell = this.props.expandableOptions ? (this.props.expandableOptions.treeDepth * 10) : 0;
344-
if (this.props.expandableOptions && this.props.expandableOptions.canExpand) {
345-
cellExpander = (<span style={{float: 'left', marginLeft: marginLeft}} onClick={this.onCellExpand}>{this.props.expandableOptions.expanded ? String.fromCharCode('9660') : String.fromCharCode('9658')}</span>);
354+
if (this.canExpand()) {
355+
cellExpander = (<span style={{float: 'left', marginLeft: marginLeft}} onClick={this.onCellExpand} >{this.props.expandableOptions.expanded ? String.fromCharCode('9660') : String.fromCharCode('9658')}</span>);
346356
}
347357
return (<div ref="cell"
348358
className="react-grid-Cell__value">{cellExpander}<span style={{float: 'left', marginLeft: marginLeftCell}}>{CellContent}</span> {this.props.cellControls} </div>);
@@ -363,7 +373,7 @@ const Cell = React.createClass({
363373
let dragHandle = (!this.isActive() && this.canEdit()) ? <div className="drag-handle" draggable="true" onDoubleClick={this.onDragHandleDoubleClick}><span style={{display: 'none'}}></span></div> : null;
364374

365375
return (
366-
<div {...this.props} className={className} style={style} onClick={this.onCellClick} onDoubleClick={this.onCellDoubleClick} onDragOver={this.onDragOver}>
376+
<div {...this.props} className={className} style={style} onKeyDown={this.onCellKeyDown} onClick={this.onCellClick} onDoubleClick={this.onCellDoubleClick} onDragOver={this.onDragOver}>
367377
{cellContent}
368378
{dragHandle}
369379
</div>

0 commit comments

Comments
 (0)