Skip to content

Commit e922d7f

Browse files
committed
Take padding into account when calculating lineheight
The helper function getLineHeight calculates the height of a contextmenu entry by mocking two entries and divide the height of the container by two. But this does not take the padding of the container into account. Padding must be substracted from the offsetHeight.
1 parent d80615e commit e922d7f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/helpers/dom.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ export function getLineHeight(container: HTMLDivElement): number {
3434
cloned.append(element2);
3535
container.parentNode?.append(cloned);
3636

37-
const height = cloned.offsetHeight / 2;
37+
const clonedStyle = window.getComputedStyle(cloned);
38+
const paddingTop = Number.parseInt(clonedStyle.paddingTop, 10);
39+
const paddingBottom = Number.parseInt(clonedStyle.paddingBottom, 10);
40+
41+
const height = (cloned.offsetHeight - (paddingTop + paddingBottom)) / 2;
3842

3943
container.parentNode?.removeChild(cloned);
4044

0 commit comments

Comments
 (0)