@@ -183,6 +183,17 @@ import { ContextMenuMixin } from './vaadin-context-menu-mixin.js';
183
183
* `overlay` | The overlay container
184
184
* `content` | The overlay content
185
185
*
186
+ * ### Custom CSS Properties
187
+ *
188
+ * The following custom CSS properties are available for styling:
189
+ *
190
+ * Custom CSS property | Description
191
+ * --------------------------------------|-------------
192
+ * `--vaadin-context-menu-offset-top` | Used as an offset when using `position` and the context menu is aligned vertically below the target
193
+ * `--vaadin-context-menu-offset-bottom` | Used as an offset when using `position` and the context menu is aligned vertically above the target
194
+ * `--vaadin-context-menu-offset-start` | Used as an offset when using `position` and the context menu is aligned horizontally after the target
195
+ * `--vaadin-context-menu-offset-end` | Used as an offset when using `position` and the context menu is aligned horizontally before the target
196
+ *
186
197
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
187
198
*
188
199
* ### Internal components
@@ -226,17 +237,39 @@ class ContextMenu extends ContextMenuMixin(ElementMixin(ThemePropertyMixin(Polyl
226
237
` ;
227
238
}
228
239
240
+ static get properties ( ) {
241
+ return {
242
+ /**
243
+ * Position of the overlay with respect to the target.
244
+ * Supported values: null, `top-start`, `top`, `top-end`,
245
+ * `bottom-start`, `bottom`, `bottom-end`, `start-top`,
246
+ * `start`, `start-bottom`, `end-top`, `end`, `end-bottom`.
247
+ */
248
+ position : {
249
+ type : String ,
250
+ } ,
251
+ } ;
252
+ }
253
+
229
254
/** @protected */
230
255
render ( ) {
256
+ const { _context : context , position } = this ;
257
+
231
258
return html `
232
259
< slot id ="slot "> </ slot >
233
260
< vaadin-context-menu-overlay
234
261
id ="overlay "
235
262
.owner ="${ this } "
236
263
.opened ="${ this . opened } "
237
- .model ="${ this . _context } "
264
+ .model ="${ context } "
238
265
.modeless ="${ this . _modeless } "
239
266
.renderer ="${ this . items ? this . __itemsRenderer : this . renderer } "
267
+ .position ="${ position } "
268
+ .positionTarget ="${ position ? context && context . target : this . _positionTarget } "
269
+ .horizontalAlign ="${ this . __computeHorizontalAlign ( position ) } "
270
+ .verticalAlign ="${ this . __computeVerticalAlign ( position ) } "
271
+ ?no-horizontal-overlap ="${ this . __computeNoHorizontalOverlap ( position ) } "
272
+ ?no-vertical-overlap ="${ this . __computeNoVerticalOverlap ( position ) } "
240
273
.withBackdrop ="${ this . _phone } "
241
274
?phone ="${ this . _phone } "
242
275
theme ="${ ifDefined ( this . _theme ) } "
@@ -251,6 +284,42 @@ class ContextMenu extends ContextMenuMixin(ElementMixin(ThemePropertyMixin(Polyl
251
284
` ;
252
285
}
253
286
287
+ /** @private */
288
+ __computeHorizontalAlign ( position ) {
289
+ if ( ! position ) {
290
+ return 'start' ;
291
+ }
292
+
293
+ return [ 'top-end' , 'bottom-end' , 'start-top' , 'start' , 'start-bottom' ] . includes ( position ) ? 'end' : 'start' ;
294
+ }
295
+
296
+ /** @private */
297
+ __computeNoHorizontalOverlap ( position ) {
298
+ if ( ! position ) {
299
+ return ! ! this . _positionTarget ;
300
+ }
301
+
302
+ return [ 'start-top' , 'start' , 'start-bottom' , 'end-top' , 'end' , 'end-bottom' ] . includes ( position ) ;
303
+ }
304
+
305
+ /** @private */
306
+ __computeNoVerticalOverlap ( position ) {
307
+ if ( ! position ) {
308
+ return false ;
309
+ }
310
+
311
+ return [ 'top-start' , 'top-end' , 'top' , 'bottom-start' , 'bottom' , 'bottom-end' ] . includes ( position ) ;
312
+ }
313
+
314
+ /** @private */
315
+ __computeVerticalAlign ( position ) {
316
+ if ( ! position ) {
317
+ return 'top' ;
318
+ }
319
+
320
+ return [ 'top-start' , 'top-end' , 'top' , 'start-bottom' , 'end-bottom' ] . includes ( position ) ? 'bottom' : 'top' ;
321
+ }
322
+
254
323
/**
255
324
* Fired when an item is selected when the context menu is populated using the `items` API.
256
325
*
0 commit comments