Răsfoiți Sursa

Aligned the getPositionedAncestor() to its name. It now considers element ancestors only.

Aleksander Nowodzinski 5 ani în urmă
părinte
comite
28a0bb7a7f

+ 6 - 22
packages/ckeditor5-utils/src/dom/getpositionedancestor.js

@@ -16,29 +16,13 @@ import global from './global';
  * @returns {HTMLElement|null}
  * @returns {HTMLElement|null}
  */
  */
 export default function getPositionedAncestor( element ) {
 export default function getPositionedAncestor( element ) {
-	while ( element && element.tagName.toLowerCase() != 'html' ) {
-		if ( global.window.getComputedStyle( element ).position != 'static' ) {
-			return element;
-		}
+	if ( !element || !element.parentNode ) {
+		return null;
+	}
 
 
-		element = element.parentElement;
+	if ( element.offsetParent === global.document.body ) {
+		return null;
 	}
 	}
 
 
-	return null;
+	return element.offsetParent;
 }
 }
-
-// export default function getPositionedAncestor( element ) {
-// 	if ( !element || !element.parentNode ) {
-// 		return null;
-// 	}
-
-// 	if ( element.style.position && element.style.position !== 'static' ) {
-// 		return element;
-// 	}
-
-// 	if ( element.offsetParent === global.document.body ) {
-// 		return null;
-// 	}
-
-// 	return element.offsetParent;
-// }

+ 3 - 3
packages/ckeditor5-utils/tests/dom/getpositionedancestor.js

@@ -24,14 +24,14 @@ describe( 'getPositionedAncestor', () => {
 		expect( getPositionedAncestor() ).to.be.null;
 		expect( getPositionedAncestor() ).to.be.null;
 	} );
 	} );
 
 
-	it( 'should return null when there is no parent', () => {
+	it( 'should return null when there is no positioned ancestor', () => {
 		expect( getPositionedAncestor( element ) ).to.be.null;
 		expect( getPositionedAncestor( element ) ).to.be.null;
 	} );
 	} );
 
 
-	it( 'should consider passed element', () => {
+	it( 'should not consider the passed element', () => {
 		element.style.position = 'relative';
 		element.style.position = 'relative';
 
 
-		expect( getPositionedAncestor( element ) ).to.equal( element );
+		expect( getPositionedAncestor( element ) ).to.be.null;
 	} );
 	} );
 
 
 	it( 'should find the positioned ancestor (direct parent)', () => {
 	it( 'should find the positioned ancestor (direct parent)', () => {