@vaadin/item 22.0.0-beta1 → 22.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -22
- package/package.json +8 -7
- package/src/vaadin-item-mixin.d.ts +14 -23
- package/src/vaadin-item-mixin.js +57 -79
- package/src/vaadin-item.js +1 -1
- package/theme/lumo/vaadin-item-styles.js +1 -1
- package/theme/material/vaadin-item-styles.js +1 -1
package/README.md
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @vaadin/item
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
|
5
|
-
[API documentation ↗](https://vaadin.com/components/vaadin-item/html-api)
|
|
3
|
+
A web component for displaying items in list-box, context-menu or select components.
|
|
6
4
|
|
|
7
|
-
[
|
|
5
|
+
[Documentation + Live Demo ↗](https://vaadin.com/components/vaadin-item/html-examples)
|
|
8
6
|
|
|
9
7
|
[](https://www.npmjs.com/package/@vaadin/item)
|
|
10
|
-
[](https://vaadin.com/directory/component/vaadinvaadin-item)
|
|
11
8
|
[](https://discord.gg/PHmkCKC)
|
|
12
9
|
|
|
13
10
|
```html
|
|
@@ -18,37 +15,40 @@
|
|
|
18
15
|
|
|
19
16
|
## Installation
|
|
20
17
|
|
|
21
|
-
Install
|
|
18
|
+
Install the component:
|
|
22
19
|
|
|
23
20
|
```sh
|
|
24
|
-
npm i @vaadin/item
|
|
21
|
+
npm i @vaadin/item
|
|
25
22
|
```
|
|
26
23
|
|
|
27
|
-
Once installed, import
|
|
24
|
+
Once installed, import the component in your application:
|
|
28
25
|
|
|
29
26
|
```js
|
|
30
|
-
import '@vaadin/item
|
|
27
|
+
import '@vaadin/item';
|
|
31
28
|
```
|
|
32
29
|
|
|
33
|
-
##
|
|
30
|
+
## Themes
|
|
34
31
|
|
|
35
|
-
Vaadin components
|
|
32
|
+
Vaadin components come with two built-in [themes](https://vaadin.com/docs/latest/ds/customization/using-themes), Lumo and Material.
|
|
33
|
+
The [main entrypoint](https://github.com/vaadin/web-components/blob/master/packages/item/vaadin-item.js) of the package uses Lumo theme.
|
|
36
34
|
|
|
37
|
-
To use the Material theme, import the
|
|
35
|
+
To use the Material theme, import the component from the `theme/material` folder:
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`theme/lumo/vaadin-item.js`
|
|
37
|
+
```js
|
|
38
|
+
import '@vaadin/item/theme/material/vaadin-item.js';
|
|
39
|
+
```
|
|
44
40
|
|
|
45
|
-
|
|
41
|
+
You can also import the Lumo version of the component explicitly:
|
|
46
42
|
|
|
47
|
-
|
|
43
|
+
```js
|
|
44
|
+
import '@vaadin/item/theme/lumo/vaadin-item.js';
|
|
45
|
+
```
|
|
48
46
|
|
|
49
|
-
-
|
|
47
|
+
Finally, you can import the un-themed component from the `src` folder to get a minimal starting point:
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
```js
|
|
50
|
+
import '@vaadin/item/src/vaadin-item.js';
|
|
51
|
+
```
|
|
52
52
|
|
|
53
53
|
## Contributing
|
|
54
54
|
|
|
@@ -57,3 +57,6 @@ Read the [contributing guide](https://vaadin.com/docs/latest/guide/contributing/
|
|
|
57
57
|
## License
|
|
58
58
|
|
|
59
59
|
Apache License 2.0
|
|
60
|
+
|
|
61
|
+
Vaadin collects usage statistics at development time to improve this product.
|
|
62
|
+
For details and to opt-out, see https://github.com/vaadin/vaadin-usage-statistics.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/item",
|
|
3
|
-
"version": "22.0.
|
|
3
|
+
"version": "22.0.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,16 +32,17 @@
|
|
|
32
32
|
"polymer"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
35
36
|
"@polymer/polymer": "^3.0.0",
|
|
36
|
-
"@vaadin/component-base": "22.0.
|
|
37
|
-
"@vaadin/vaadin-lumo-styles": "22.0.
|
|
38
|
-
"@vaadin/vaadin-material-styles": "22.0.
|
|
39
|
-
"@vaadin/vaadin-themable-mixin": "22.0.
|
|
37
|
+
"@vaadin/component-base": "^22.0.1",
|
|
38
|
+
"@vaadin/vaadin-lumo-styles": "^22.0.1",
|
|
39
|
+
"@vaadin/vaadin-material-styles": "^22.0.1",
|
|
40
|
+
"@vaadin/vaadin-themable-mixin": "^22.0.1"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@esm-bundle/chai": "^4.3.4",
|
|
43
|
-
"@vaadin/testing-helpers": "^0.3.
|
|
44
|
+
"@vaadin/testing-helpers": "^0.3.2",
|
|
44
45
|
"sinon": "^9.2.1"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "2b0a2bff0369d6020f7cc33ad35506aa2d1f6f68"
|
|
47
48
|
}
|
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import { Constructor } from '@open-wc/dedupe-mixin';
|
|
7
|
+
import { ActiveMixinClass } from '@vaadin/component-base/src/active-mixin.js';
|
|
8
|
+
import { DisabledMixinClass } from '@vaadin/component-base/src/disabled-mixin.js';
|
|
9
|
+
import { FocusMixinClass } from '@vaadin/component-base/src/focus-mixin.js';
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* A mixin providing `focused`, `focus-ring`, `active`, `disabled` and `selected`.
|
|
9
13
|
*
|
|
10
14
|
* `focused`, `active` and `focus-ring` are set as only as attributes.
|
|
11
15
|
*/
|
|
12
|
-
declare function ItemMixin<T extends
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
export declare function ItemMixin<T extends Constructor<HTMLElement>>(
|
|
17
|
+
base: T
|
|
18
|
+
): T &
|
|
19
|
+
Constructor<ItemMixinClass> &
|
|
20
|
+
Constructor<ActiveMixinClass> &
|
|
21
|
+
Constructor<DisabledMixinClass> &
|
|
22
|
+
Constructor<FocusMixinClass>;
|
|
23
|
+
|
|
24
|
+
export declare class ItemMixinClass {
|
|
19
25
|
value: string;
|
|
20
26
|
|
|
21
27
|
/**
|
|
@@ -23,25 +29,10 @@ interface ItemMixin {
|
|
|
23
29
|
* e.g. in VaadinListMixin it filters items by using the
|
|
24
30
|
* `element._hasVaadinItemMixin` condition.
|
|
25
31
|
*/
|
|
26
|
-
_hasVaadinItemMixin: boolean;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* If true, the user cannot interact with this element.
|
|
30
|
-
*/
|
|
31
|
-
disabled: boolean;
|
|
32
|
+
protected _hasVaadinItemMixin: boolean;
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* If true, the item is in selected state.
|
|
35
36
|
*/
|
|
36
37
|
selected: boolean;
|
|
37
|
-
|
|
38
|
-
_setFocused(focused: boolean): void;
|
|
39
|
-
|
|
40
|
-
_setActive(active: boolean): void;
|
|
41
|
-
|
|
42
|
-
_onKeydown(event: KeyboardEvent): void;
|
|
43
|
-
|
|
44
|
-
_onKeyup(event: KeyboardEvent): void;
|
|
45
38
|
}
|
|
46
|
-
|
|
47
|
-
export { ItemMixin, ItemMixinConstructor };
|
package/src/vaadin-item-mixin.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
+
import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js';
|
|
7
|
+
import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* A mixin providing `focused`, `focus-ring`, `active`, `disabled` and `selected`.
|
|
@@ -11,7 +13,7 @@
|
|
|
11
13
|
* @polymerMixin
|
|
12
14
|
*/
|
|
13
15
|
export const ItemMixin = (superClass) =>
|
|
14
|
-
class VaadinItemMixin extends superClass {
|
|
16
|
+
class VaadinItemMixin extends ActiveMixin(FocusMixin(superClass)) {
|
|
15
17
|
static get properties() {
|
|
16
18
|
return {
|
|
17
19
|
/**
|
|
@@ -24,17 +26,6 @@ export const ItemMixin = (superClass) =>
|
|
|
24
26
|
value: true
|
|
25
27
|
},
|
|
26
28
|
|
|
27
|
-
/**
|
|
28
|
-
* If true, the user cannot interact with this element.
|
|
29
|
-
* @type {boolean}
|
|
30
|
-
*/
|
|
31
|
-
disabled: {
|
|
32
|
-
type: Boolean,
|
|
33
|
-
value: false,
|
|
34
|
-
observer: '_disabledChanged',
|
|
35
|
-
reflectToAttribute: true
|
|
36
|
-
},
|
|
37
|
-
|
|
38
29
|
/**
|
|
39
30
|
* If true, the item is in selected state.
|
|
40
31
|
* @type {boolean}
|
|
@@ -51,6 +42,18 @@ export const ItemMixin = (superClass) =>
|
|
|
51
42
|
};
|
|
52
43
|
}
|
|
53
44
|
|
|
45
|
+
/**
|
|
46
|
+
* By default, `Space` is the only possible activation key for a focusable HTML element.
|
|
47
|
+
* Nonetheless, the item is an exception as it can be also activated by pressing `Enter`.
|
|
48
|
+
* See the "Keyboard Support" section in https://www.w3.org/TR/wai-aria-practices/examples/menubar/menubar-1/menubar-1.html.
|
|
49
|
+
*
|
|
50
|
+
* @protected
|
|
51
|
+
* @override
|
|
52
|
+
*/
|
|
53
|
+
get _activeKeys() {
|
|
54
|
+
return ['Enter', ' '];
|
|
55
|
+
}
|
|
56
|
+
|
|
54
57
|
/**
|
|
55
58
|
* @return {string}
|
|
56
59
|
*/
|
|
@@ -73,31 +76,30 @@ export const ItemMixin = (superClass) =>
|
|
|
73
76
|
if (attrValue !== null) {
|
|
74
77
|
this.value = attrValue;
|
|
75
78
|
}
|
|
76
|
-
|
|
77
|
-
this.addEventListener('focus', () => this._setFocused(true), true);
|
|
78
|
-
this.addEventListener('blur', () => this._setFocused(false), true);
|
|
79
|
-
this.addEventListener('mousedown', () => {
|
|
80
|
-
this._setActive((this._mousedown = true));
|
|
81
|
-
const mouseUpListener = () => {
|
|
82
|
-
this._setActive((this._mousedown = false));
|
|
83
|
-
document.removeEventListener('mouseup', mouseUpListener);
|
|
84
|
-
};
|
|
85
|
-
document.addEventListener('mouseup', mouseUpListener);
|
|
86
|
-
});
|
|
87
|
-
this.addEventListener('keydown', (e) => this._onKeydown(e));
|
|
88
|
-
this.addEventListener('keyup', (e) => this._onKeyup(e));
|
|
89
79
|
}
|
|
90
80
|
|
|
91
|
-
/**
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (this.
|
|
99
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Override native `focus` to set focused attribute
|
|
83
|
+
* when focusing the item programmatically.
|
|
84
|
+
* @protected
|
|
85
|
+
* @override
|
|
86
|
+
*/
|
|
87
|
+
focus() {
|
|
88
|
+
if (this.disabled) {
|
|
89
|
+
return;
|
|
100
90
|
}
|
|
91
|
+
|
|
92
|
+
super.focus();
|
|
93
|
+
this._setFocused(true);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @param {KeyboardEvent | MouseEvent} _event
|
|
98
|
+
* @protected
|
|
99
|
+
* @override
|
|
100
|
+
*/
|
|
101
|
+
_shouldSetActive(event) {
|
|
102
|
+
return !this.disabled && !(event.type === 'keydown' && event.defaultPrevented);
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
/** @private */
|
|
@@ -105,64 +107,40 @@ export const ItemMixin = (superClass) =>
|
|
|
105
107
|
this.setAttribute('aria-selected', selected);
|
|
106
108
|
}
|
|
107
109
|
|
|
108
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* Override an observer from `DisabledMixin`.
|
|
112
|
+
* @protected
|
|
113
|
+
* @override
|
|
114
|
+
*/
|
|
109
115
|
_disabledChanged(disabled) {
|
|
116
|
+
super._disabledChanged(disabled);
|
|
117
|
+
|
|
110
118
|
if (disabled) {
|
|
111
119
|
this.selected = false;
|
|
112
|
-
this.setAttribute('aria-disabled', 'true');
|
|
113
120
|
this.blur();
|
|
114
|
-
} else {
|
|
115
|
-
this.removeAttribute('aria-disabled');
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* @param {boolean} focused
|
|
121
|
-
* @protected
|
|
122
|
-
*/
|
|
123
|
-
_setFocused(focused) {
|
|
124
|
-
if (focused) {
|
|
125
|
-
this.setAttribute('focused', '');
|
|
126
|
-
if (!this._mousedown) {
|
|
127
|
-
this.setAttribute('focus-ring', '');
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
this.removeAttribute('focused');
|
|
131
|
-
this.removeAttribute('focus-ring');
|
|
132
|
-
this._setActive(false);
|
|
133
121
|
}
|
|
134
122
|
}
|
|
135
123
|
|
|
136
124
|
/**
|
|
137
|
-
*
|
|
125
|
+
* In order to be fully accessible from the keyboard, the item should
|
|
126
|
+
* manually fire the `click` event once an activation key is pressed.
|
|
127
|
+
*
|
|
128
|
+
* According to the UI Events specifications,
|
|
129
|
+
* the `click` event should be fired exactly on `keydown`:
|
|
130
|
+
* https://www.w3.org/TR/uievents/#event-type-keydown
|
|
131
|
+
*
|
|
132
|
+
* @param {KeyboardEvent} event
|
|
138
133
|
* @protected
|
|
134
|
+
* @override
|
|
139
135
|
*/
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
this.setAttribute('active', '');
|
|
143
|
-
} else {
|
|
144
|
-
this.removeAttribute('active');
|
|
145
|
-
}
|
|
146
|
-
}
|
|
136
|
+
_onKeyDown(event) {
|
|
137
|
+
super._onKeyDown(event);
|
|
147
138
|
|
|
148
|
-
|
|
149
|
-
* @param {!KeyboardEvent} event
|
|
150
|
-
* @protected
|
|
151
|
-
*/
|
|
152
|
-
_onKeydown(event) {
|
|
153
|
-
if (/^( |SpaceBar|Enter)$/.test(event.key) && !event.defaultPrevented) {
|
|
139
|
+
if (this._activeKeys.includes(event.key) && !event.defaultPrevented) {
|
|
154
140
|
event.preventDefault();
|
|
155
|
-
this._setActive(true);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
141
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
* @protected
|
|
162
|
-
*/
|
|
163
|
-
_onKeyup() {
|
|
164
|
-
if (this.hasAttribute('active')) {
|
|
165
|
-
this._setActive(false);
|
|
142
|
+
// `DisabledMixin` overrides the standard `click()` method
|
|
143
|
+
// so that it doesn't fire the `click` event when the element is disabled.
|
|
166
144
|
this.click();
|
|
167
145
|
}
|
|
168
146
|
}
|
package/src/vaadin-item.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Copyright (c) 2021 Vaadin Ltd.
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
7
|
import { DirMixin } from '@vaadin/component-base/src/dir-mixin.js';
|
|
8
8
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
9
9
|
import { ItemMixin } from './vaadin-item-mixin.js';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
|
|
2
1
|
import '@vaadin/vaadin-lumo-styles/font-icons.js';
|
|
3
2
|
import '@vaadin/vaadin-lumo-styles/sizing.js';
|
|
4
3
|
import '@vaadin/vaadin-lumo-styles/spacing.js';
|
|
5
4
|
import '@vaadin/vaadin-lumo-styles/style.js';
|
|
6
5
|
import '@vaadin/vaadin-lumo-styles/typography.js';
|
|
6
|
+
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
7
7
|
|
|
8
8
|
const item = css`
|
|
9
9
|
:host {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { registerStyles, css } from '@vaadin/vaadin-themable-mixin/register-styles.js';
|
|
2
1
|
import '@vaadin/vaadin-material-styles/font-icons.js';
|
|
3
2
|
import '@vaadin/vaadin-material-styles/color.js';
|
|
4
3
|
import '@vaadin/vaadin-material-styles/typography.js';
|
|
4
|
+
import { css, registerStyles } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
5
5
|
|
|
6
6
|
const item = css`
|
|
7
7
|
:host {
|