Skip to content

Commit

Permalink
Merge pull request #3515 from marmelab/disabled-input-use-input
Browse files Browse the repository at this point in the history
[RFR] Migrate DisabledInput to use useInput
  • Loading branch information
Kmaschta authored Aug 13, 2019
2 parents 398fb0b + 1f5dbe1 commit bd4ca73
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions packages/ra-ui-materialui/src/input/DisabledInput.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,46 @@
import React from 'react';
import PropTypes from 'prop-types';
import TextField from '@material-ui/core/TextField';
import { addField, FieldTitle } from 'ra-core';
import { useInput, FieldTitle } from 'ra-core';

import sanitizeRestProps from './sanitizeRestProps';

const DisabledInput = ({
classes,
className,
record,
input: { value },
label,
resource,
source,
options,
...rest
}) => (
<TextField
disabled
margin="normal"
value={value}
label={<FieldTitle label={label} source={source} resource={resource} />}
className={className}
classes={classes}
{...options}
{...sanitizeRestProps(rest)}
/>
);
}) => {
const {
id,
input: { value },
} = useInput({
resource,
source,
});

return (
<TextField
id={id}
value={value}
disabled
margin="normal"
label={
<FieldTitle label={label} source={source} resource={resource} />
}
{...options}
{...sanitizeRestProps(rest)}
/>
);
};

DisabledInput.propTypes = {
classes: PropTypes.object,
className: PropTypes.string,
label: PropTypes.string,
input: PropTypes.object,
options: PropTypes.object,
record: PropTypes.object,
resource: PropTypes.string,
source: PropTypes.string,
};

export default addField(DisabledInput);
export default DisabledInput;

0 comments on commit bd4ca73

Please sign in to comment.