Reputation: 903
Trying to set the height and width of an imagefield, and it enforces it on the surrounding container but not on the image itself.
const styles = {
profile: { height: 50, width: 50 }
}
export const UserList = withStyles(styles)(({ classes, permissions, ...props }) => (
<List actions={<UserListActions />} sort={{ field: 'lastName', order: 'ASC' }} title="All users" {...props} bulkActions={false}>
<Datagrid>
<ImageField source="imageUrl" label="Profile Picture" className={classes.profile} />
Upvotes: 2
Views: 3272
Reputation: 703
Recommended way of doing it is this
<ImageField
source="imageUrl" label="Profile Picture"
sx={{ '& img': { maxWidth: 50, maxHeight: 50, objectFit: 'contain' } }}
/>
Upvotes: 0
Reputation: 346
This also works:
import { makeStyles } from '@material-ui/core/styles';
const useImageFieldStyles = makeStyles(theme => ({
image: { // This will override the style of the <img> inside the <div>
width: 50,
height: 50,
}
}));
const PostEdit = ({ permissions, ...props }) => {
const imageFieldClasses = useImageFieldStyles();
return (
// ...
<ImageInput multiple source="pictures" accept="image/*">
<ImageField classes={imageFieldClasses} source="src" title="title" />
</ImageInput>
// ...
);
};
From: https://github.com/marmelab/react-admin/issues/3106#issuecomment-658752706
Upvotes: 2
Reputation: 903
Figured this out. Was just doing it wrong:
const styles = {
image: { maxHeight: '3rem' }
}
export const UserList = withStyles(styles)(({ classes, permissions, ...props }) => (
<List actions={<UserListActions />} sort={{ field: 'lastName', order: 'ASC' }} title="All users" {...props} bulkActions={false}>
<Datagrid>
<ImageField classes={classes} source="imageUrl" label="Profile Picture" />
Upvotes: 9