Skip to content

Commit

Permalink
Take padding into account when calculating lineheight
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hw-df committed Oct 2, 2024
1 parent d80615e commit e922d7f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/helpers/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ export function getLineHeight(container: HTMLDivElement): number {
cloned.append(element2);
container.parentNode?.append(cloned);

const height = cloned.offsetHeight / 2;
const clonedStyle = window.getComputedStyle(cloned);
const paddingTop = Number.parseInt(clonedStyle.paddingTop, 10);
const paddingBottom = Number.parseInt(clonedStyle.paddingBottom, 10);

const height = (cloned.offsetHeight - (paddingTop + paddingBottom)) / 2;

container.parentNode?.removeChild(cloned);

Expand Down

0 comments on commit e922d7f

Please sign in to comment.