Skip to content

Commit

Permalink
fix ControlHOC ref for redux container widgets
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
erquhart committed Nov 12, 2017
1 parent fdeeb44 commit a4ff229
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/components/Widgets/ControlHOC.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/components/Widgets/RelationControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,9 @@ export default connect(
{
query,
clearSearch,
},
null,
{
withRef: true,
}
)(RelationControl);

0 comments on commit a4ff229

Please sign in to comment.