Skip to content

Commit c29bfc3

Browse files
anezthesjouni
andauthored
experiment: add context-menu base styles and visual tests (#9642)
Co-authored-by: Jouni Koivuviita <jouni@vaadin.com>
1 parent ca6a71c commit c29bfc3

16 files changed

+212
-7
lines changed

packages/context-menu/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
"lit.d.ts",
2424
"lit.js",
2525
"src",
26+
"!src/styles/*-base-styles.d.ts",
27+
"!src/styles/*-base-styles.js",
2628
"theme",
2729
"vaadin-*.d.ts",
2830
"vaadin-*.js",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const contextMenuItemStyles: CSSResult;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import '@vaadin/component-base/src/style-props.js';
7+
import { css } from 'lit';
8+
import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-base-styles.js';
9+
10+
const menuItemStyles = css`
11+
:host::after {
12+
background: var(--vaadin-color-subtle);
13+
content: '';
14+
display: block;
15+
height: var(--vaadin-icon-size, 1lh);
16+
mask-image: var(--_vaadin-icon-chevron-down);
17+
rotate: -90deg;
18+
visibility: hidden;
19+
width: var(--vaadin-icon-size, 1lh);
20+
}
21+
22+
:host([dir='rtl'])::after {
23+
rotate: 90deg;
24+
}
25+
26+
/* TODO would be nice to only reserve the space for these if
27+
one or mote items in the list is checkable or has child items */
28+
:host([aria-haspopup='true'])::after,
29+
:host([menu-item-checked]) [part='checkmark'] {
30+
visibility: visible;
31+
}
32+
`;
33+
34+
export const contextMenuItemStyles = [itemStyles, menuItemStyles];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const contextMenuItemStyles: CSSResult;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-core-styles.js';
7+
8+
export const contextMenuItemStyles = [itemStyles];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const contextMenuOverlayStyles: CSSResult;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { overlayStyles } from '@vaadin/overlay/src/styles/vaadin-overlay-base-styles.js';
7+
import { menuOverlayStyles } from './vaadin-menu-overlay-base-styles.js';
8+
9+
export const contextMenuOverlayStyles = [overlayStyles, menuOverlayStyles];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import type { CSSResult } from 'lit';
7+
8+
export const menuOverlayStyles: CSSResult;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2016 - 2025 Vaadin Ltd.
4+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
5+
*/
6+
import { css } from 'lit';
7+
8+
export const menuOverlayStyles = css`
9+
:host {
10+
align-items: flex-start;
11+
justify-content: flex-start;
12+
}
13+
14+
:host([right-aligned]),
15+
:host([end-aligned]) {
16+
align-items: flex-end;
17+
}
18+
19+
:host([bottom-aligned]) {
20+
justify-content: flex-end;
21+
}
22+
23+
[part='content'] {
24+
padding: var(--vaadin-item-overlay-padding, 4px);
25+
}
26+
27+
/* TODO keyboard focus becomes visible even when navigating the menu with the mouse */
28+
[part='overlay']:focus-visible {
29+
outline: none;
30+
}
31+
`;

packages/context-menu/src/vaadin-context-menu-item.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { html, LitElement } from 'lit';
77
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
88
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
99
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
10-
import { itemStyles } from '@vaadin/item/src/styles/vaadin-item-core-styles.js';
1110
import { ItemMixin } from '@vaadin/item/src/vaadin-item-mixin.js';
1211
import { LumoInjectionMixin } from '@vaadin/vaadin-themable-mixin/lumo-injection-mixin.js';
1312
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
13+
import { contextMenuItemStyles } from './styles/vaadin-context-menu-item-core-styles.js';
1414

1515
/**
1616
* An element used internally by `<vaadin-context-menu>`. Not intended to be used separately.
@@ -28,7 +28,7 @@ class ContextMenuItem extends ItemMixin(ThemableMixin(DirMixin(LumoInjectionMixi
2828
}
2929

3030
static get styles() {
31-
return itemStyles;
31+
return contextMenuItemStyles;
3232
}
3333

3434
/** @protected */

0 commit comments

Comments
 (0)