Skip to content

Commit 15b4f30

Browse files
committed
Use ID as a namespace to increase specificity
1 parent 7a1afba commit 15b4f30

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

packages/block-editor/src/components/image-editor/v2/aspect-ratio-dropdown.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function presetRatioAsNumber( { ratio, ...rest } ) {
5656

5757
export default function AspectRatioDropdown( { toggleProps } ) {
5858
const {
59-
state: { image, cropper },
59+
state: { image, cropper, isAspectRatioLocked },
6060
dispatch,
6161
} = useImageCropper();
6262
const defaultAspect = image.width / image.height;
@@ -89,7 +89,7 @@ export default function AspectRatioDropdown( { toggleProps } ) {
8989
}
9090
onClose();
9191
} }
92-
value={ aspectRatio }
92+
value={ isAspectRatioLocked ? aspectRatio : 0 }
9393
aspectRatios={ [
9494
// All ratios should be mirrored in AspectRatioTool in @wordpress/block-editor.
9595
{

packages/components/src/image-cropper/component.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ const Cropper = forwardRef< HTMLDivElement >( ( {}, ref ) => {
190190

191191
return (
192192
<MaxWidthWrapper
193+
// Disable reason: We're using this ID as a namespace only to increase CSS specificity for this component.
194+
// eslint-disable-next-line no-restricted-syntax
195+
id="components-image-cropper"
193196
style={ {
194197
width: isAxisSwapped
195198
? `${ originalHeight }px`
@@ -232,6 +235,10 @@ const Cropper = forwardRef< HTMLDivElement >( ( {}, ref ) => {
232235
crossOrigin="anonymous"
233236
isResizing={ isResizing }
234237
isDragging={ isDragging }
238+
style={ {
239+
width: `${ image.width }px`,
240+
height: `${ image.height }px`,
241+
} }
235242
/>
236243
<CropWindow>
237244
<ContainWindow>
@@ -242,6 +249,10 @@ const Cropper = forwardRef< HTMLDivElement >( ( {}, ref ) => {
242249
alt=""
243250
crossOrigin="anonymous"
244251
ref={ imageRef }
252+
style={ {
253+
width: `${ image.width }px`,
254+
height: `${ image.height }px`,
255+
} }
245256
/>
246257
</ContainWindow>
247258
</CropWindow>

packages/components/src/image-cropper/styles.tsx

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ export const Resizable = styled( MotionResizable )`
9797
export const MaxWidthWrapper = styled.div`
9898
position: relative;
9999
max-width: 100%;
100-
101100
min-width: 0;
102101
`;
103102

@@ -115,19 +114,25 @@ export const ContainWindow = styled.div`
115114
`;
116115

117116
export const Img = styled( motion.img )`
118-
position: absolute;
119-
pointer-events: none;
120-
top: 50%;
121-
left: 50%;
122-
transform-origin: center center;
123-
rotate: var( --wp-cropper-angle );
124-
scale: var( --wp-cropper-scale-x ) var( --wp-cropper-scale-y );
125-
translate: calc(
126-
var( --wp-cropper-image-x ) - var( --wp-cropper-window-x ) - 50%
127-
)
128-
calc( var( --wp-cropper-image-y ) - var( --wp-cropper-window-y ) - 50% );
129-
will-change: rotate, scale, translate;
130-
contain: strict;
117+
// Using a "namespace" ID to increase CSS specificity for this component.
118+
#components-image-cropper & {
119+
position: absolute;
120+
pointer-events: none;
121+
top: 50%;
122+
left: 50%;
123+
transform-origin: center center;
124+
rotate: var( --wp-cropper-angle );
125+
scale: var( --wp-cropper-scale-x ) var( --wp-cropper-scale-y );
126+
translate: calc(
127+
var( --wp-cropper-image-x ) - var( --wp-cropper-window-x ) - 50%
128+
)
129+
calc(
130+
var( --wp-cropper-image-y ) - var( --wp-cropper-window-y ) - 50%
131+
);
132+
will-change: rotate, scale, translate;
133+
contain: strict;
134+
max-width: none;
135+
}
131136
`;
132137

133138
export const BackgroundImg = styled( Img, {

0 commit comments

Comments
 (0)