fix ControlHOC ref for redux container widgets
If a widget uses `connect` to receive state updates from the store, `ControlHOC` can no longer get the control instance ref. This fix checks for this case and uses a connect option to obtain the wrapped control ref.
This commit is contained in:
@ -36,8 +36,17 @@ class ControlHOC extends Component {
|
|||||||
return this.props.value !== nextProps.value;
|
return this.props.value !== nextProps.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
processInnerControlRef = (wrappedControl) => {
|
processInnerControlRef = ref => {
|
||||||
if (!wrappedControl) return;
|
if (!ref) return;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the widget is a container that receives state updates from the store,
|
||||||
|
* we'll need to get the ref of the actual control via the `react-redux`
|
||||||
|
* `getWrappedInstance` method. Note that connected widgets must pass
|
||||||
|
* `withRef: true` to `connect` in the options object.
|
||||||
|
*/
|
||||||
|
const wrappedControl = ref.getWrappedInstance ? ref.getWrappedInstance() : ref;
|
||||||
|
|
||||||
this.wrappedControlValid = wrappedControl.isValid || truthy;
|
this.wrappedControlValid = wrappedControl.isValid || truthy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -128,5 +128,9 @@ export default connect(
|
|||||||
{
|
{
|
||||||
query,
|
query,
|
||||||
clearSearch,
|
clearSearch,
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
{
|
||||||
|
withRef: true,
|
||||||
}
|
}
|
||||||
)(RelationControl);
|
)(RelationControl);
|
||||||
|
Reference in New Issue
Block a user