Skip to content

Commit 4a918f6

Browse files
authored
fix(react-image): ensure height and width props always applied (microsoft#35161)
1 parent 656f694 commit 4a918f6

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix: apply fit fill styles only if height and width are not provided",
4+
"packageName": "@fluentui/react-image",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/react-components/react-image/library/src/components/Image/useImageStyles.styles.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,26 @@ const useStyles = makeStyles({
3939
center: {
4040
objectFit: 'none',
4141
objectPosition: 'center',
42-
height: '100%',
43-
width: '100%',
4442
},
4543
contain: {
4644
objectFit: 'contain',
4745
objectPosition: 'center',
48-
height: '100%',
49-
width: '100%',
5046
},
5147
default: {
5248
/* The default styles are exactly the same as the base styles. */
5349
},
5450
cover: {
5551
objectFit: 'cover',
5652
objectPosition: 'center',
57-
height: '100%',
58-
width: '100%',
5953
},
6054
none: {
6155
objectFit: 'none',
6256
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: {
6362
height: '100%',
6463
width: '100%',
6564
},
@@ -75,13 +74,19 @@ export const useImageStyles_unstable = (state: ImageState): ImageState => {
7574

7675
const styles = useStyles();
7776

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+
7882
state.root.className = mergeClasses(
7983
imageClassNames.root,
8084
styles.base,
8185
state.block && styles.block,
8286
state.bordered && styles.bordered,
8387
state.shadow && styles.shadow,
8488
styles[state.fit],
89+
shouldApplyFitFill && styles.fitFill,
8590
styles[state.shape],
8691
state.root.className,
8792
);

0 commit comments

Comments
 (0)