Skip to content

Commit

Permalink
fix(richtext-lexical): fixed the positioning of the button to add col…
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanJablo authored Feb 7, 2025
1 parent a80c6b5 commit 886bd94
Showing 1 changed file with 40 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,37 +91,46 @@ function TableHoverActionsContainer({
{ editor },
)

if (tableDOMElement) {
const {
bottom: tableElemBottom,
height: tableElemHeight,
left: tableElemLeft,
right: tableElemRight,
width: tableElemWidth,
y: tableElemY,
} = (tableDOMElement as HTMLTableElement).getBoundingClientRect()
if (!tableDOMElement) {
return
}

const { left: editorElemLeft, y: editorElemY } = anchorElem.getBoundingClientRect()
// this is the scrollable div container of the table (in case of overflow)
const tableContainerElement = (tableDOMElement as HTMLTableElement).parentElement

if (hoveredRowNode) {
setShownColumn(false)
setShownRow(true)
setPosition({
height: BUTTON_WIDTH_PX,
left: tableElemLeft - editorElemLeft,
top: tableElemBottom - editorElemY + 5,
width: tableElemWidth,
})
} else if (hoveredColumnNode) {
setShownColumn(true)
setShownRow(false)
setPosition({
height: tableElemHeight,
left: tableElemRight - editorElemLeft + 5,
top: tableElemY - editorElemY,
width: BUTTON_WIDTH_PX,
})
}
if (!tableContainerElement) {
return
}

const {
bottom: tableElemBottom,
height: tableElemHeight,
left: tableElemLeft,
right: tableElemRight,
width: tableElemWidth,
y: tableElemY,
} = tableContainerElement.getBoundingClientRect()

const { left: editorElemLeft, y: editorElemY } = anchorElem.getBoundingClientRect()

if (hoveredRowNode) {
setShownColumn(false)
setShownRow(true)
setPosition({
height: BUTTON_WIDTH_PX,
left: tableElemLeft - editorElemLeft,
top: tableElemBottom - editorElemY + 5,
width: tableElemWidth,
})
} else if (hoveredColumnNode) {
setShownColumn(true)
setShownRow(false)
setPosition({
height: tableElemHeight,
left: tableElemRight - editorElemLeft + 5,
top: tableElemY - editorElemY,
width: BUTTON_WIDTH_PX,
})
}
},
50,
Expand Down Expand Up @@ -218,6 +227,7 @@ function TableHoverActionsContainer({
<>
{isShownRow && (
<button
aria-label="Add Row"
className={editorConfig.editorConfig.lexical.theme.tableAddRows}
onClick={() => insertAction(true)}
style={{ ...position }}
Expand All @@ -226,6 +236,7 @@ function TableHoverActionsContainer({
)}
{isShownColumn && (
<button
aria-label="Add Column"
className={editorConfig.editorConfig.lexical.theme.tableAddColumns}
onClick={() => insertAction(false)}
style={{ ...position }}
Expand Down

0 comments on commit 886bd94

Please sign in to comment.