Kaynağa Gözat

Updated how the getPositionedAncestor() is used in the getOptimalPosition() because it no longer considers the passed element. Refactoring in tests.

Aleksander Nowodzinski 5 yıl önce
ebeveyn
işleme
50bb75c2e5

+ 1 - 1
packages/ckeditor5-utils/src/dom/position.js

@@ -90,7 +90,7 @@ export function getOptimalPosition( { element, target, positions, limiter, fitIn
 		limiter = limiter();
 	}
 
-	const positionedElementAncestor = getPositionedAncestor( element.parentElement );
+	const positionedElementAncestor = getPositionedAncestor( element );
 	const elementRect = new Rect( element );
 	const targetRect = new Rect( target );
 

+ 10 - 11
packages/ckeditor5-utils/tests/dom/position.js

@@ -237,20 +237,19 @@ describe( 'getOptimalPosition()', () => {
 				}, {
 					position: 'absolute',
 					borderLeftWidth: '20px',
-					borderTopWidth: '40px'
+					borderTopWidth: '40px',
+					overflow: 'scroll',
+					width: '10px',
+					height: '10px',
+					background: 'red'
 				} );
 
 				Object.assign( element.style, {
 					width: '20px',
 					height: '20px',
 					marginTop: '100px',
-					marginLeft: '200px'
-				} );
-
-				Object.assign( parent.style, {
-					overflow: 'scroll',
-					width: '10px',
-					height: '10px'
+					marginLeft: '200px',
+					background: 'green'
 				} );
 
 				parent.appendChild( element );
@@ -260,8 +259,8 @@ describe( 'getOptimalPosition()', () => {
 				parent.scrollTop = 100;
 
 				assertPosition( { element, target, positions: [ attachLeftBottom ] }, {
-					top: 160,
-					left: 260,
+					top: 200,
+					left: 280,
 					name: 'left-bottom'
 				} );
 			} );
@@ -696,7 +695,7 @@ function getElement( rect = {}, styles = {} ) {
 		styles.borderTopWidth = '0px';
 	}
 
-	window.getComputedStyle.withArgs( element ).returns( styles );
+	Object.assign( element.style, styles );
 
 	return element;
 }