Update grid context menu position determination to work regardless of page scroll offsets
This commit is contained in:
parent
7486d3dde0
commit
2df810c59b
|
@ -82,6 +82,11 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Disable pointer events for non-focused cells */
|
||||||
|
.cell:not(.focused) :global(*) {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
/* Cell border */
|
/* Cell border */
|
||||||
.cell.focused:after,
|
.cell.focused:after,
|
||||||
.cell.error:after,
|
.cell.error:after,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { writable, get } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
import { GutterWidth } from "../lib/constants"
|
import { tick } from "svelte"
|
||||||
|
|
||||||
export const createStores = () => {
|
export const createStores = () => {
|
||||||
const menu = writable({
|
const menu = writable({
|
||||||
|
@ -14,18 +14,25 @@ export const createStores = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deriveStores = context => {
|
export const deriveStores = context => {
|
||||||
const { menu, bounds, focusedCellId, stickyColumn, rowHeight } = context
|
const { menu, focusedCellId, rand } = context
|
||||||
|
|
||||||
const open = (cellId, e) => {
|
const open = (cellId, e) => {
|
||||||
const $bounds = get(bounds)
|
|
||||||
const $stickyColumn = get(stickyColumn)
|
|
||||||
const $rowHeight = get(rowHeight)
|
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
// Get DOM node for grid data wrapper to compute relative position to
|
||||||
|
const gridNode = document.getElementById(`grid-${rand}`)
|
||||||
|
const dataNode = gridNode?.getElementsByClassName("grid-data-outer")?.[0]
|
||||||
|
if (!dataNode) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute bounds of cell relative to outer data node
|
||||||
|
const targetBounds = e.target.getBoundingClientRect()
|
||||||
|
const dataBounds = dataNode.getBoundingClientRect()
|
||||||
focusedCellId.set(cellId)
|
focusedCellId.set(cellId)
|
||||||
menu.set({
|
menu.set({
|
||||||
left:
|
left: targetBounds.left - dataBounds.left + e.offsetX,
|
||||||
e.clientX - $bounds.left + GutterWidth + ($stickyColumn?.width || 0),
|
top: targetBounds.top - dataBounds.top + e.offsetY,
|
||||||
top: e.clientY - $bounds.top + $rowHeight,
|
|
||||||
visible: true,
|
visible: true,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue