Skip to content

Commit 8c7a34a

Browse files
authored
Merge pull request #131 from b97822302002/master
Expose the onFocus event to custom components
2 parents 9fb2316 + f4047e7 commit 8c7a34a

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/lib/EasyCustom.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default class EasyCustom extends Component {
88
};
99
this.setValue = this.setValue.bind(this);
1010
this.onBlur = this.onBlur.bind(this);
11+
this.onFocus = this.onFocus.bind(this);
1112
}
1213

1314
setValue(value) {
@@ -20,6 +21,10 @@ export default class EasyCustom extends Component {
2021
this.props.onBlur();
2122
}
2223

24+
onFocus() {
25+
this.props.onFocus();
26+
}
27+
2328
render() {
2429
const { value } = this.state;
2530
const { children, cssClassPrefix } = this.props;
@@ -28,6 +33,7 @@ export default class EasyCustom extends Component {
2833
{
2934
setParentValue: this.setValue,
3035
onBlur : this.onBlur,
36+
onFocus : this.onFocus,
3137
value
3238
}
3339
);

src/lib/EasyCustom.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('EasyCustom', () => {
1212
const setValueFunction = jest.fn();
1313
const blurFn = jest.fn();
1414
const saveFn = jest.fn();
15+
const focusFn = jest.fn();
1516

1617
it('should initially set the value passed in as the state value', () => {
1718
wrapper = shallow(
@@ -64,6 +65,18 @@ describe('EasyCustom', () => {
6465
expect(blurFn).toBeCalled();
6566
});
6667

68+
it('should trigger the onFocus fn when custom component gains focus', () => {
69+
wrapper = mount(
70+
<EasyEdit
71+
type="text"
72+
onFocus={focusFn}
73+
editComponent={<CustomComponent />}
74+
/>);
75+
wrapper.simulate('click');
76+
wrapper.find('input').simulate('focus');
77+
expect(focusFn).toBeCalled();
78+
});
79+
6780
});
6881

6982
class CustomComponent extends React.Component{

src/lib/EasyEdit.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ export default class EasyEdit extends React.Component {
151151
<EasyCustom
152152
setValue={this.onChange}
153153
onBlur={this._onBlur}
154+
onFocus={this._onFocus()}
154155
value={this.state.tempValue}
155156
cssClassPrefix={cssClassPrefix}
156157
>

0 commit comments

Comments
 (0)