-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1437 from microsoft/u/juliaroldi/z-index
Get biggest z index of element
- Loading branch information
Showing
3 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/roosterjs-editor-plugins/lib/plugins/ImageEdit/editInfoUtils/getLastZIndex.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { getTagOfNode } from 'roosterjs-editor-dom'; | ||
|
||
/** | ||
* @internal | ||
* Search through from editor div to it's root for the latest z-index value | ||
* @param editorDiv the editor div element | ||
* @returns the z index value | ||
*/ | ||
export default function getLatestZIndex(editorDiv: HTMLElement) { | ||
let child: HTMLElement | null = editorDiv; | ||
let zIndex = 0; | ||
while (child && getTagOfNode(child) !== 'BODY') { | ||
if (child.style.zIndex) { | ||
zIndex = parseInt(child.style.zIndex); | ||
} | ||
child = child.parentElement; | ||
} | ||
return zIndex; | ||
} |
36 changes: 36 additions & 0 deletions
36
packages/roosterjs-editor-plugins/test/imageEdit/getLastZIndexTest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import getLatestZIndex from '../../lib/plugins/ImageEdit/editInfoUtils/getLastZIndex'; | ||
|
||
describe('getLatestZIndex', () => { | ||
function runTest(element: HTMLElement, expected: number) { | ||
const result = getLatestZIndex(element); | ||
expect(result).toBe(expected); | ||
} | ||
|
||
it('should return parentNode zIndex', () => { | ||
const div = document.createElement('div'); | ||
div.style.zIndex = '20'; | ||
const span = document.createElement('span'); | ||
span.style.zIndex = '10'; | ||
div.appendChild(span); | ||
runTest(span, 20); | ||
}); | ||
|
||
it('should return child zIndex', () => { | ||
const div = document.createElement('div'); | ||
const span = document.createElement('span'); | ||
span.style.zIndex = '30'; | ||
div.appendChild(span); | ||
runTest(span, 30); | ||
}); | ||
|
||
it('should return middle element zIndex', () => { | ||
const div = document.createElement('div'); | ||
const spanParent = document.createElement('div'); | ||
spanParent.style.zIndex = '30'; | ||
div.appendChild(spanParent); | ||
const span = document.createElement('span'); | ||
span.style.zIndex = '20'; | ||
spanParent.appendChild(span); | ||
runTest(span, 30); | ||
}); | ||
}); |