From 990642b34f4e21f813a92646d3d74280b671b6f6 Mon Sep 17 00:00:00 2001 From: Gildas Garcia Date: Mon, 19 Aug 2019 12:57:27 +0200 Subject: [PATCH] [RFR] Migrate ReferenceInput to use useInput --- .../src/input/ReferenceInput.js | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/ra-ui-materialui/src/input/ReferenceInput.js b/packages/ra-ui-materialui/src/input/ReferenceInput.js index b46bd68bb9..a012a643e1 100644 --- a/packages/ra-ui-materialui/src/input/ReferenceInput.js +++ b/packages/ra-ui-materialui/src/input/ReferenceInput.js @@ -1,6 +1,6 @@ import React, { Children, cloneElement } from 'react'; import PropTypes from 'prop-types'; -import { addField, useReferenceInputController } from 'ra-core'; +import { useInput, useReferenceInputController } from 'ra-core'; import LinearProgress from '../layout/LinearProgress'; import Labeled from './Labeled'; @@ -85,9 +85,28 @@ import ReferenceError from './ReferenceError'; * * */ -export const ReferenceInput = props => ( - -); +export const ReferenceInput = ({ + onBlur, + onChange, + onFocus, + validate, + ...props +}) => { + const inputProps = useInput({ + onBlur, + onChange, + onFocus, + validate, + ...props, + }); + return ( + + ); +}; ReferenceInput.propTypes = { allowEmpty: PropTypes.bool.isRequired, @@ -97,14 +116,12 @@ ReferenceInput.propTypes = { classes: PropTypes.object, filter: PropTypes.object, filterToQuery: PropTypes.func.isRequired, - input: PropTypes.object.isRequired, label: PropTypes.string, - meta: PropTypes.object, onChange: PropTypes.func, perPage: PropTypes.number, record: PropTypes.object, reference: PropTypes.string.isRequired, - resource: PropTypes.string.isRequired, + resource: PropTypes.string, sort: PropTypes.shape({ field: PropTypes.string, order: PropTypes.oneOf(['ASC', 'DESC']), @@ -120,8 +137,6 @@ ReferenceInput.defaultProps = { sort: { field: 'id', order: 'DESC' }, }; -const EnhancedReferenceInput = addField(ReferenceInput); - const sanitizeRestProps = ({ allowEmpty, basePath, @@ -248,4 +263,4 @@ ReferenceInputView.propTypes = { warning: PropTypes.string, }; -export default EnhancedReferenceInput; +export default ReferenceInput;