@@ -18,7 +18,8 @@ import {
18
18
MENU_VERTICAL_PADDING ,
19
19
MENU_WIDTH ,
20
20
} from "../../constants" ;
21
- import { DOMCoordinates , MenuMouseEvent , Pixel , SpreadsheetChildEnv , UID } from "../../types" ;
21
+ import { DOMCoordinates , MenuMouseEvent , Pixel , Rect , SpreadsheetChildEnv , UID } from "../../types" ;
22
+ import { PopoverPropsPosition } from "../../types/cell_popovers" ;
22
23
import { css , cssPropertiesToCss } from "../helpers/css" ;
23
24
import { getOpenedMenus , isChildEvent , isMiddleClickOrCtrlClick } from "../helpers/dom_helpers" ;
24
25
import { useAbsoluteBoundingRect } from "../helpers/position_hook" ;
@@ -81,7 +82,8 @@ type MenuItemOrSeparator = Action | "separator";
81
82
const TIMEOUT_DELAY = 250 ;
82
83
83
84
interface Props {
84
- position : DOMCoordinates ;
85
+ anchorRect : Rect ;
86
+ popoverPositioning : PopoverPropsPosition ;
85
87
menuItems : Action [ ] ;
86
88
depth : number ;
87
89
maxHeight ?: Pixel ;
@@ -95,7 +97,7 @@ interface Props {
95
97
export interface MenuState {
96
98
isOpen : boolean ;
97
99
parentMenu ?: Action ;
98
- position : null | DOMCoordinates ;
100
+ anchorRect : null | Rect ;
99
101
scrollOffset ?: Pixel ;
100
102
menuItems : Action [ ] ;
101
103
isHoveringChild ?: boolean ;
@@ -104,7 +106,8 @@ export interface MenuState {
104
106
export class Menu extends Component < Props , SpreadsheetChildEnv > {
105
107
static template = "o-spreadsheet-Menu" ;
106
108
static props = {
107
- position : Object ,
109
+ anchorRect : Object ,
110
+ popoverPositioning : { type : String , optional : true } ,
108
111
menuItems : Array ,
109
112
depth : { type : Number , optional : true } ,
110
113
maxHeight : { type : Number , optional : true } ,
@@ -118,10 +121,11 @@ export class Menu extends Component<Props, SpreadsheetChildEnv> {
118
121
static components = { Menu, Popover } ;
119
122
static defaultProps = {
120
123
depth : 1 ,
124
+ popoverPositioning : "TopRight" ,
121
125
} ;
122
126
private subMenu : MenuState = useState ( {
123
127
isOpen : false ,
124
- position : null ,
128
+ anchorRect : null ,
125
129
scrollOffset : 0 ,
126
130
menuItems : [ ] ,
127
131
isHoveringChild : false ,
@@ -170,22 +174,22 @@ export class Menu extends Component<Props, SpreadsheetChildEnv> {
170
174
return menuItemsAndSeparators ;
171
175
}
172
176
173
- get subMenuPosition ( ) : DOMCoordinates {
174
- const position = Object . assign ( { } , this . subMenu . position ) ;
175
- position . y -= this . subMenu . scrollOffset || 0 ;
176
- return position ;
177
+ get subMenuAnchorRect ( ) : Rect {
178
+ const anchorRect = Object . assign ( { } , this . subMenu . anchorRect ) ;
179
+ anchorRect . y -= this . subMenu . scrollOffset || 0 ;
180
+ return anchorRect ;
177
181
}
178
182
179
183
get popoverProps ( ) : PopoverProps {
180
184
const isRoot = this . props . depth === 1 ;
181
185
return {
182
186
anchorRect : {
183
- x : this . props . position . x ,
184
- y : this . props . position . y ,
185
- width : isRoot ? 0 : this . props . width || MENU_WIDTH ,
186
- height : isRoot ? 0 : MENU_ITEM_HEIGHT ,
187
+ x : this . props . anchorRect . x ,
188
+ y : this . props . anchorRect . y ,
189
+ width : isRoot ? this . props . anchorRect . width : this . props . width || MENU_WIDTH ,
190
+ height : isRoot ? this . props . anchorRect . height : MENU_ITEM_HEIGHT ,
187
191
} ,
188
- positioning : "TopRight" ,
192
+ positioning : this . props . popoverPositioning ,
189
193
verticalOffset : isRoot ? 0 : MENU_VERTICAL_PADDING ,
190
194
onPopoverHidden : ( ) => this . closeSubMenu ( ) ,
191
195
onPopoverMoved : ( ) => this . closeSubMenu ( ) ,
@@ -269,9 +273,11 @@ export class Menu extends Component<Props, SpreadsheetChildEnv> {
269
273
}
270
274
const y = parentMenuEl . getBoundingClientRect ( ) . top ;
271
275
272
- this . subMenu . position = {
276
+ this . subMenu . anchorRect = {
273
277
x : this . position . x ,
274
278
y : y - ( this . subMenu . scrollOffset || 0 ) ,
279
+ width : this . props . width || MENU_WIDTH ,
280
+ height : MENU_ITEM_HEIGHT ,
275
281
} ;
276
282
this . subMenu . menuItems = menu . children ( this . env ) ;
277
283
this . subMenu . isOpen = true ;
0 commit comments