Skip to content

Commit 64a5bed

Browse files
committed
addition of HANDLE_EDITOR_FOCUS and HANDLE_EDITOR_BLUR methods per #98
1 parent 7e08b5d commit 64a5bed

File tree

5 files changed

+69
-20
lines changed

5 files changed

+69
-20
lines changed

README.MD

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ export const events = {
372372
HANDLE_AFTER_SELECT_ALL: () => {},
373373
HANDLE_AFTER_DESELECT_ALL: () => {},
374374
HANDLE_AFTER_ROW_DROP: () => {},
375-
HANDLE_BEFORE_TREE_CHILD_CREATE: () => {}
375+
HANDLE_BEFORE_TREE_CHILD_CREATE: () => {},
376+
HANDLE_EDITOR_FOCUS: () => {},
377+
HANDLE_EDITOR_BLUR: () => {}
376378
};
377379
```
378380

demo/demoData.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ export const events = {
5050
},
5151
HANDLE_AFTER_ROW_DROP: ({ treeData, row }) => {
5252
console.log('After drag and drop of row event');
53+
},
54+
HANDLE_EDITOR_FOCUS: (a) => {
55+
console.log(a)
56+
console.log('Handle editor focus');
57+
},
58+
HANDLE_EDITOR_BLUR: () => {
59+
console.log('Handle editor blur');
5360
}
5461
};
5562

src/components/layout/table-row/row/Cell.jsx

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,8 @@ export const Cell = ({
7777
shouldNest ? 'tree-nested' : '',
7878
depth !== null ? `tree-node-depth-${depth}` : ''
7979
),
80-
onClick: (e) => {
81-
return handleClick(cellClickArguments, e);
82-
},
83-
onDoubleClick: (e) => {
84-
return handleDoubleClick(cellClickArguments, e);
85-
},
80+
onClick: (e) => handleClick(cellClickArguments, e),
81+
onDoubleClick: (e) => handleDoubleClick(cellClickArguments, e),
8682
style: {}
8783
};
8884

@@ -117,13 +113,14 @@ export const Cell = ({
117113

118114
const cellHTML = getCellHTML(
119115
cellData,
116+
columns,
120117
editorState,
118+
events,
119+
index,
121120
isEditable,
122121
isRowSelected,
123-
columns,
124-
index,
125-
rowId,
126122
row,
123+
rowId,
127124
stateKey,
128125
store
129126
);
@@ -144,13 +141,14 @@ export const Cell = ({
144141

145142
export const getCellHTML = (
146143
cellData,
144+
columns,
147145
editorState,
146+
events,
147+
index,
148148
isEditable,
149149
isRowSelected,
150-
columns,
151-
index,
152-
rowId,
153150
row,
151+
rowId,
154152
stateKey,
155153
store
156154
) => {
@@ -161,6 +159,7 @@ export const getCellHTML = (
161159
cellData={cellData}
162160
columns={columns}
163161
editorState={editorState}
162+
events={events}
164163
index={index}
165164
isEditable={isEditable}
166165
isRowSelected={isRowSelected}

src/components/layout/table-row/row/cell/Editor.jsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React, { PropTypes } from 'react';
22
import { Input } from './Input';
33
import { gridConfig } from './../../../../../constants/GridConstants';
44
import { prefix } from './../../../../../util/prefix';
5+
import { fireEvent } from './../../../../../util/fire';
56
import { nameFromDataIndex } from './../../../../../util/getData';
67

78
export const Editor = ({
89
cellData,
910
columns,
1011
editorState,
12+
events,
1113
rawValue,
1214
index,
1315
isEditable,
@@ -58,6 +60,26 @@ export const Editor = ({
5860
invalid ? CLASS_NAMES.EDITOR.INVALID : ''
5961
);
6062

63+
const onFocus = () => fireEvent(
64+
'HANDLE_EDITOR_FOCUS',
65+
events,
66+
{
67+
column: columns[index],
68+
rowId,
69+
editor: editorData
70+
}
71+
);
72+
73+
const onBlur = () => fireEvent(
74+
'HANDLE_EDITOR_BLUR',
75+
events,
76+
{
77+
column: columns[index],
78+
rowId,
79+
editor: editorData
80+
}
81+
);
82+
6183
if (isEditable
6284
&& columns[index]
6385
&& columns[index].editor
@@ -73,6 +95,8 @@ export const Editor = ({
7395
columns,
7496
store,
7597
rowId,
98+
onFocus,
99+
onBlur,
76100
row: editorData && editorData.values && editorData.toJS
77101
? { ...row, ...cleanProps(editorData.values.toJS()) }
78102
: { key: rowId, ...row },
@@ -104,6 +128,8 @@ export const Editor = ({
104128
column={columns[index]}
105129
columns={columns}
106130
editorState={editorState}
131+
onBlur={onBlur}
132+
onFocus={onFocus}
107133
rowId={rowId}
108134
stateKey={stateKey}
109135
store={store}
@@ -130,6 +156,7 @@ Editor.propTypes = {
130156
cellData: any,
131157
columns: array,
132158
editorState: object,
159+
events: object,
133160
index: number,
134161
isEditable: bool,
135162
isRowSelected: bool,

src/components/layout/table-row/row/cell/Input.jsx

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@ import {
1212
Editor
1313
} from './../../../../../records';
1414

15+
const {
16+
any,
17+
array,
18+
func,
19+
object,
20+
string
21+
} = PropTypes;
22+
1523
export const Input = ({
1624
cellData,
1725
column,
1826
columns,
1927
editorState,
28+
onBlur,
29+
onFocus,
2030
rowId,
2131
stateKey,
2232
store
@@ -56,7 +66,9 @@ export const Input = ({
5666
return (
5767
<input
5868
disabled={disabled}
69+
onBlur={onBlur}
5970
onChange={onChange}
71+
onFocus={onFocus}
6072
placeholder={placeholder}
6173
type="text"
6274
value={value}
@@ -81,11 +93,13 @@ export const handleChange = (
8193
};
8294

8395
Input.propTypes = {
84-
cellData: PropTypes.any,
85-
column: PropTypes.object,
86-
columns: PropTypes.array,
87-
editorState: PropTypes.object,
88-
rowId: PropTypes.string,
89-
stateKey: PropTypes.string,
90-
store: PropTypes.object
96+
cellData: any,
97+
column: object,
98+
columns: array,
99+
editorState: object,
100+
onBlur: func,
101+
onFocus: func,
102+
rowId: string,
103+
stateKey: string,
104+
store: object
91105
};

0 commit comments

Comments
 (0)