@@ -799,6 +799,35 @@ function TableCellActionMenuContainer({
799
799
800
800
const [ colorPickerModal , showColorPickerModal ] = useModal ( ) ;
801
801
802
+ const checkTableCellOverflow = useCallback (
803
+ ( tableCellParentNodeDOM : HTMLElement ) : boolean => {
804
+ const scrollableContainer = tableCellParentNodeDOM . closest (
805
+ '.PlaygroundEditorTheme__tableScrollableWrapper' ,
806
+ ) ;
807
+ if ( scrollableContainer ) {
808
+ const containerRect = (
809
+ scrollableContainer as HTMLElement
810
+ ) . getBoundingClientRect ( ) ;
811
+ const cellRect = tableCellParentNodeDOM . getBoundingClientRect ( ) ;
812
+
813
+ // Calculate where the action button would be positioned (5px from right edge of cell)
814
+ // Also account for the button width and table cell padding (8px)
815
+ const actionButtonRight = cellRect . right - 5 ;
816
+ const actionButtonLeft = actionButtonRight - 28 ; // 20px width + 8px padding
817
+
818
+ // Only hide if the action button would overflow the container
819
+ if (
820
+ actionButtonRight > containerRect . right ||
821
+ actionButtonLeft < containerRect . left
822
+ ) {
823
+ return true ;
824
+ }
825
+ }
826
+ return false ;
827
+ } ,
828
+ [ ] ,
829
+ ) ;
830
+
802
831
const $moveMenu = useCallback ( ( ) => {
803
832
const menu = menuButtonRef . current ;
804
833
const selection = $getSelection ( ) ;
@@ -845,6 +874,10 @@ function TableCellActionMenuContainer({
845
874
return disable ( ) ;
846
875
}
847
876
877
+ if ( checkTableCellOverflow ( tableCellParentNodeDOM ) ) {
878
+ return disable ( ) ;
879
+ }
880
+
848
881
const tableNode = $getTableNodeFromLexicalNodeOrThrow (
849
882
tableCellNodeFromSelection ,
850
883
) ;
@@ -879,6 +912,14 @@ function TableCellActionMenuContainer({
879
912
) ;
880
913
tableObserver = getTableObserverFromTableElement ( tableElement ) ;
881
914
tableCellParentNodeDOM = editor . getElementByKey ( anchorNode . getKey ( ) ) ;
915
+
916
+ if ( tableCellParentNodeDOM === null ) {
917
+ return disable ( ) ;
918
+ }
919
+
920
+ if ( checkTableCellOverflow ( tableCellParentNodeDOM ) ) {
921
+ return disable ( ) ;
922
+ }
882
923
} else if ( ! activeElement ) {
883
924
return disable ( ) ;
884
925
}
@@ -901,7 +942,7 @@ function TableCellActionMenuContainer({
901
942
const left = tableCellRect . right - anchorRect . left ;
902
943
menu . style . transform = `translate(${ left } px, ${ top } px)` ;
903
944
}
904
- } , [ editor , anchorElem ] ) ;
945
+ } , [ editor , anchorElem , checkTableCellOverflow ] ) ;
905
946
906
947
useEffect ( ( ) => {
907
948
// We call the $moveMenu callback every time the selection changes,
0 commit comments