@@ -39,27 +39,26 @@ const useStyles = makeStyles({
39
39
center : {
40
40
objectFit : 'none' ,
41
41
objectPosition : 'center' ,
42
- height : '100%' ,
43
- width : '100%' ,
44
42
} ,
45
43
contain : {
46
44
objectFit : 'contain' ,
47
45
objectPosition : 'center' ,
48
- height : '100%' ,
49
- width : '100%' ,
50
46
} ,
51
47
default : {
52
48
/* The default styles are exactly the same as the base styles. */
53
49
} ,
54
50
cover : {
55
51
objectFit : 'cover' ,
56
52
objectPosition : 'center' ,
57
- height : '100%' ,
58
- width : '100%' ,
59
53
} ,
60
54
none : {
61
55
objectFit : 'none' ,
62
56
objectPosition : 'left top' ,
57
+ } ,
58
+
59
+ // When no explicit height/width props are provided, apply full-size
60
+ // sizing so fit modes behave as intended (object-fit fills the element).
61
+ fitFill : {
63
62
height : '100%' ,
64
63
width : '100%' ,
65
64
} ,
@@ -75,13 +74,19 @@ export const useImageStyles_unstable = (state: ImageState): ImageState => {
75
74
76
75
const styles = useStyles ( ) ;
77
76
77
+ const { height, width } = state . root ;
78
+ // eslint-disable-next-line eqeqeq
79
+ const hasExplicitSize = height != null || width != null ;
80
+ const shouldApplyFitFill = state . fit !== 'default' && ! hasExplicitSize ;
81
+
78
82
state . root . className = mergeClasses (
79
83
imageClassNames . root ,
80
84
styles . base ,
81
85
state . block && styles . block ,
82
86
state . bordered && styles . bordered ,
83
87
state . shadow && styles . shadow ,
84
88
styles [ state . fit ] ,
89
+ shouldApplyFitFill && styles . fitFill ,
85
90
styles [ state . shape ] ,
86
91
state . root . className ,
87
92
) ;
0 commit comments