Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFR] Migrate DisabledInput to use useInput #3515

Merged
merged 2 commits into from
Aug 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;