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:
Shawn Erquhart 2017-11-11 20:57:45 -05:00
parent fdeeb44ba3
commit a4ff229e37
2 changed files with 15 additions and 2 deletions

View File

@ -36,8 +36,17 @@ class ControlHOC extends Component {
return this.props.value !== nextProps.value;
}
processInnerControlRef = (wrappedControl) => {
if (!wrappedControl) return;
processInnerControlRef = ref => {
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;
/**

View File

@ -128,5 +128,9 @@ export default connect(
{
query,
clearSearch,
},
null,
{
withRef: true,
}
)(RelationControl);