Skip to content

Commit e7948d0

Browse files
authored
Change to using transform: translate(delta) for positioning relative to current position
1 parent d628227 commit e7948d0

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/text-expander-element.ts

+3-13
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,9 @@ class TextExpander {
8585
this.expander.dispatchEvent(new Event('text-expander-activate'))
8686

8787
const caretRect = new InputRange(this.input, match.position).getBoundingClientRect()
88-
const nominalPosition = {top: caretRect.top + caretRect.height, left: caretRect.left}
89-
menu.style.top = `${nominalPosition.top}px`
90-
menu.style.left = `${nominalPosition.left}px`
91-
92-
// Nominal position is relative to entire document, but the menu could be positioned relative to a container if
93-
// it is not `fixed` or on the top layer
94-
const actualPosition = menu.getBoundingClientRect()
95-
96-
const topDelta = actualPosition.top - nominalPosition.top
97-
if (topDelta !== 0) menu.style.top = `${nominalPosition.top - topDelta}px`
98-
99-
const leftDelta = actualPosition.left - nominalPosition.left
100-
if (leftDelta !== 0) menu.style.left = `${nominalPosition.left - leftDelta}px`
88+
const currentPosition = menu.getBoundingClientRect()
89+
const delta = {x: caretRect.x - currentPosition.x, y: caretRect.y + caretRect.height - currentPosition.y}
90+
menu.style.transform = `translate(${delta.x}px, ${delta.y}px)`
10191

10292
this.combobox.start()
10393
menu.addEventListener('combobox-commit', this.oncommit)

0 commit comments

Comments
 (0)