File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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
6982class CustomComponent extends React . Component {
Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments