Skip to content

Commit 49ae0c4

Browse files
authored
experiment: add list-box base styles and visual tests (#9186)
1 parent ab5118c commit 49ae0c4

12 files changed

+132
-34
lines changed

packages/list-box/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
"type": "module",
2222
"files": [
2323
"src",
24+
"!src/*-base-styles.d.ts",
25+
"!src/*-base-styles.js",
2426
"theme",
2527
"vaadin-*.d.ts",
2628
"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) 2017 - 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 listBoxStyles: CSSResult;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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+
9+
export const listBoxStyles = css`
10+
:host {
11+
--vaadin-item-checkmark-display: block;
12+
display: flex;
13+
}
14+
15+
:host([hidden]) {
16+
display: none !important;
17+
}
18+
19+
[part='items'] {
20+
height: 100%;
21+
overflow-y: auto;
22+
width: 100%;
23+
}
24+
25+
[part='items'] ::slotted(hr) {
26+
border-color: var(--vaadin-divider-color, var(--_vaadin-border-color));
27+
border-width: 0 0 1px;
28+
margin: 4px 8px;
29+
margin-inline-start: calc(
30+
var(--vaadin-icon-size, 1lh) + var(--vaadin-item-gap, var(--_vaadin-gap-container-inline)) + 8px
31+
);
32+
}
33+
`;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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 listBoxStyles: CSSResult;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license
3+
* Copyright (c) 2017 - 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 listBoxStyles = css`
9+
:host {
10+
display: flex;
11+
}
12+
13+
:host([hidden]) {
14+
display: none !important;
15+
}
16+
17+
[part='items'] {
18+
height: 100%;
19+
width: 100%;
20+
overflow-y: auto;
21+
-webkit-overflow-scrolling: touch;
22+
}
23+
`;

packages/list-box/src/vaadin-list-box.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import { ControllerMixin } from '@vaadin/component-base/src/controller-mixin.js'
88
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
99
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
1010
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
11-
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
11+
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12+
import { listBoxStyles } from './vaadin-list-box-core-styles.js';
1213
import { MultiSelectListMixin } from './vaadin-multi-select-list-mixin.js';
1314

15+
registerStyles('vaadin-list-box', listBoxStyles, { moduleId: 'vaadin-list-box-styles' });
16+
1417
/**
1518
* `<vaadin-list-box>` is a Web Component for creating menus.
1619
*
@@ -47,22 +50,6 @@ import { MultiSelectListMixin } from './vaadin-multi-select-list-mixin.js';
4750
class ListBox extends ElementMixin(MultiSelectListMixin(ThemableMixin(ControllerMixin(PolymerElement)))) {
4851
static get template() {
4952
return html`
50-
<style>
51-
:host {
52-
display: flex;
53-
}
54-
55-
:host([hidden]) {
56-
display: none !important;
57-
}
58-
59-
[part='items'] {
60-
height: 100%;
61-
width: 100%;
62-
overflow-y: auto;
63-
-webkit-overflow-scrolling: touch;
64-
}
65-
</style>
6653
<div part="items">
6754
<slot></slot>
6855
</div>

packages/list-box/src/vaadin-lit-list-box.js

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Copyright (c) 2017 - 2025 Vaadin Ltd.
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
6-
import { css, html, LitElement } from 'lit';
6+
import { html, LitElement } from 'lit';
77
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
88
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
99
import { PolylitMixin } from '@vaadin/component-base/src/polylit-mixin.js';
1010
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
1111
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
12+
import { listBoxStyles } from './vaadin-list-box-core-styles.js';
1213
import { MultiSelectListMixin } from './vaadin-multi-select-list-mixin.js';
1314

1415
/**
@@ -26,22 +27,7 @@ class ListBox extends ElementMixin(MultiSelectListMixin(ThemableMixin(PolylitMix
2627
}
2728

2829
static get styles() {
29-
return css`
30-
:host {
31-
display: flex;
32-
}
33-
34-
:host([hidden]) {
35-
display: none !important;
36-
}
37-
38-
[part='items'] {
39-
height: 100%;
40-
width: 100%;
41-
overflow-y: auto;
42-
-webkit-overflow-scrolling: touch;
43-
}
44-
`;
30+
return listBoxStyles;
4531
}
4632

4733
static get properties() {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { fixtureSync } from '@vaadin/testing-helpers/dist/fixture.js';
2+
import { visualDiff } from '@web/test-runner-visual-regression';
3+
import '@vaadin/item/src/vaadin-item.js';
4+
import '../../../src/vaadin-list-box.js';
5+
6+
describe('list-box', () => {
7+
let div, element;
8+
9+
beforeEach(() => {
10+
div = document.createElement('div');
11+
div.style.display = 'inline-block';
12+
div.style.padding = '10px';
13+
14+
element = fixtureSync(
15+
`
16+
<vaadin-list-box>
17+
<vaadin-item focused>Item 0</vaadin-item>
18+
<vaadin-item>Item 1</vaadin-item>
19+
<vaadin-item>Item 2</vaadin-item>
20+
<vaadin-item disabled>Item 3</vaadin-item>
21+
<hr>
22+
<vaadin-item>Item 4</vaadin-item>
23+
</vaadin-list-box>
24+
`,
25+
div,
26+
);
27+
});
28+
29+
['ltr', 'rtl'].forEach((dir) => {
30+
describe(dir, () => {
31+
before(() => {
32+
document.documentElement.setAttribute('dir', dir);
33+
});
34+
35+
after(() => {
36+
document.documentElement.removeAttribute('dir');
37+
});
38+
39+
it('basic', async () => {
40+
element.selected = 2;
41+
await visualDiff(div, `${dir}-basic`);
42+
});
43+
44+
it('multiple', async () => {
45+
element.multiple = true;
46+
element.selectedValues = [1, 2];
47+
await visualDiff(div, `${dir}-multiple`);
48+
});
49+
});
50+
});
51+
});
2.43 KB
Loading
2.49 KB
Loading

0 commit comments

Comments
 (0)