@vaadin/button 23.1.0-alpha1 → 23.1.0-alpha4
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/package.json +8 -7
- package/src/vaadin-button-mixin.d.ts +23 -0
- package/src/vaadin-button-mixin.js +83 -0
- package/src/vaadin-button.d.ts +2 -4
- package/src/vaadin-button.js +3 -61
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vaadin/button",
|
|
3
|
-
"version": "23.1.0-
|
|
3
|
+
"version": "23.1.0-alpha4",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -32,16 +32,17 @@
|
|
|
32
32
|
"web-component"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
+
"@open-wc/dedupe-mixin": "^1.3.0",
|
|
35
36
|
"@polymer/polymer": "^3.0.0",
|
|
36
|
-
"@vaadin/component-base": "23.1.0-
|
|
37
|
-
"@vaadin/vaadin-lumo-styles": "23.1.0-
|
|
38
|
-
"@vaadin/vaadin-material-styles": "23.1.0-
|
|
39
|
-
"@vaadin/vaadin-themable-mixin": "23.1.0-
|
|
37
|
+
"@vaadin/component-base": "23.1.0-alpha4",
|
|
38
|
+
"@vaadin/vaadin-lumo-styles": "23.1.0-alpha4",
|
|
39
|
+
"@vaadin/vaadin-material-styles": "23.1.0-alpha4",
|
|
40
|
+
"@vaadin/vaadin-themable-mixin": "23.1.0-alpha4"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@esm-bundle/chai": "^4.3.4",
|
|
43
44
|
"@vaadin/testing-helpers": "^0.3.2",
|
|
44
|
-
"sinon": "^
|
|
45
|
+
"sinon": "^13.0.2"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "aacdb7fe09811894751f0378ff7fb66071892c71"
|
|
47
48
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
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';
|
|
10
|
+
import { KeyboardMixinClass } from '@vaadin/component-base/src/keyboard-mixin.js';
|
|
11
|
+
import { TabindexMixinClass } from '@vaadin/component-base/src/tabindex-mixin.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A mixin providing common button functionality.
|
|
15
|
+
*/
|
|
16
|
+
export declare function ButtonMixin<T extends Constructor<HTMLElement>>(
|
|
17
|
+
base: T,
|
|
18
|
+
): T &
|
|
19
|
+
Constructor<ActiveMixinClass> &
|
|
20
|
+
Constructor<DisabledMixinClass> &
|
|
21
|
+
Constructor<FocusMixinClass> &
|
|
22
|
+
Constructor<KeyboardMixinClass> &
|
|
23
|
+
Constructor<TabindexMixinClass>;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) 2017 - 2022 Vaadin Ltd.
|
|
4
|
+
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
|
+
*/
|
|
6
|
+
import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js';
|
|
7
|
+
import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
|
|
8
|
+
import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A mixin providing common button functionality.
|
|
12
|
+
*
|
|
13
|
+
* @polymerMixin
|
|
14
|
+
* @mixes ActiveMixin
|
|
15
|
+
* @mixes FocusMixin
|
|
16
|
+
* @mixes TabindexMixin
|
|
17
|
+
*/
|
|
18
|
+
export const ButtonMixin = (superClass) =>
|
|
19
|
+
class ButtonMixinClass extends ActiveMixin(TabindexMixin(FocusMixin(superClass))) {
|
|
20
|
+
static get properties() {
|
|
21
|
+
return {
|
|
22
|
+
/**
|
|
23
|
+
* Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
|
|
24
|
+
*
|
|
25
|
+
* @override
|
|
26
|
+
* @protected
|
|
27
|
+
*/
|
|
28
|
+
tabindex: {
|
|
29
|
+
value: 0,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* By default, `Space` is the only possible activation key for a focusable HTML element.
|
|
36
|
+
* Nonetheless, the button is an exception as it can be also activated by pressing `Enter`.
|
|
37
|
+
* See the "Keyboard Support" section in https://www.w3.org/TR/wai-aria-practices/examples/button/button.html.
|
|
38
|
+
*
|
|
39
|
+
* @protected
|
|
40
|
+
* @override
|
|
41
|
+
*/
|
|
42
|
+
get _activeKeys() {
|
|
43
|
+
return ['Enter', ' '];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @protected */
|
|
47
|
+
ready() {
|
|
48
|
+
super.ready();
|
|
49
|
+
|
|
50
|
+
// By default, if the user hasn't provided a custom role,
|
|
51
|
+
// the role attribute is set to "button".
|
|
52
|
+
if (!this.hasAttribute('role')) {
|
|
53
|
+
this.setAttribute('role', 'button');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Since the button component is designed on the base of the `[role=button]` attribute,
|
|
59
|
+
* and doesn't have a native <button> inside, in order to be fully accessible from the keyboard,
|
|
60
|
+
* it should manually fire the `click` event once an activation key is pressed,
|
|
61
|
+
* as it follows from the WAI-ARIA specifications:
|
|
62
|
+
* https://www.w3.org/TR/wai-aria-practices-1.1/#button
|
|
63
|
+
*
|
|
64
|
+
* According to the UI Events specifications,
|
|
65
|
+
* the `click` event should be fired exactly on `keydown`:
|
|
66
|
+
* https://www.w3.org/TR/uievents/#event-type-keydown
|
|
67
|
+
*
|
|
68
|
+
* @param {KeyboardEvent} event
|
|
69
|
+
* @protected
|
|
70
|
+
* @override
|
|
71
|
+
*/
|
|
72
|
+
_onKeyDown(event) {
|
|
73
|
+
super._onKeyDown(event);
|
|
74
|
+
|
|
75
|
+
if (this._activeKeys.includes(event.key)) {
|
|
76
|
+
event.preventDefault();
|
|
77
|
+
|
|
78
|
+
// `DisabledMixin` overrides the standard `click()` method
|
|
79
|
+
// so that it doesn't fire the `click` event when the element is disabled.
|
|
80
|
+
this.click();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
package/src/vaadin-button.d.ts
CHANGED
|
@@ -3,11 +3,9 @@
|
|
|
3
3
|
* Copyright (c) 2017 - 2022 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
6
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
8
|
-
import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
|
|
9
|
-
import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js';
|
|
10
7
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
8
|
+
import { ButtonMixin } from './vaadin-button-mixin.js';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* `<vaadin-button>` is an accessible and customizable button that allows users to perform actions.
|
|
@@ -37,7 +35,7 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
37
35
|
*
|
|
38
36
|
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
|
|
39
37
|
*/
|
|
40
|
-
declare class Button extends
|
|
38
|
+
declare class Button extends ButtonMixin(ElementMixin(ThemableMixin(HTMLElement))) {}
|
|
41
39
|
|
|
42
40
|
declare global {
|
|
43
41
|
interface HTMLElementTagNameMap {
|
package/src/vaadin-button.js
CHANGED
|
@@ -4,11 +4,9 @@
|
|
|
4
4
|
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
|
|
5
5
|
*/
|
|
6
6
|
import { html, PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
7
|
-
import { ActiveMixin } from '@vaadin/component-base/src/active-mixin.js';
|
|
8
7
|
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
|
|
9
|
-
import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js';
|
|
10
|
-
import { TabindexMixin } from '@vaadin/component-base/src/tabindex-mixin.js';
|
|
11
8
|
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
|
|
9
|
+
import { ButtonMixin } from './vaadin-button-mixin.js';
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* `<vaadin-button>` is an accessible and customizable button that allows users to perform actions.
|
|
@@ -39,13 +37,11 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
|
|
|
39
37
|
* See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
|
|
40
38
|
*
|
|
41
39
|
* @extends HTMLElement
|
|
42
|
-
* @mixes
|
|
43
|
-
* @mixes TabindexMixin
|
|
44
|
-
* @mixes FocusMixin
|
|
40
|
+
* @mixes ButtonMixin
|
|
45
41
|
* @mixes ElementMixin
|
|
46
42
|
* @mixes ThemableMixin
|
|
47
43
|
*/
|
|
48
|
-
class Button extends
|
|
44
|
+
class Button extends ButtonMixin(ElementMixin(ThemableMixin(PolymerElement))) {
|
|
49
45
|
static get is() {
|
|
50
46
|
return 'vaadin-button';
|
|
51
47
|
}
|
|
@@ -85,10 +81,6 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM
|
|
|
85
81
|
height: 100%;
|
|
86
82
|
min-height: inherit;
|
|
87
83
|
text-shadow: inherit;
|
|
88
|
-
background: transparent;
|
|
89
|
-
padding: 0;
|
|
90
|
-
border: none;
|
|
91
|
-
box-shadow: none;
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
[part='prefix'],
|
|
@@ -115,56 +107,6 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM
|
|
|
115
107
|
</div>
|
|
116
108
|
`;
|
|
117
109
|
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* By default, `Space` is the only possible activation key for a focusable HTML element.
|
|
121
|
-
* Nonetheless, the button is an exception as it can be also activated by pressing `Enter`.
|
|
122
|
-
* See the "Keyboard Support" section in https://www.w3.org/TR/wai-aria-practices/examples/button/button.html.
|
|
123
|
-
*
|
|
124
|
-
* @protected
|
|
125
|
-
* @override
|
|
126
|
-
*/
|
|
127
|
-
get _activeKeys() {
|
|
128
|
-
return ['Enter', ' '];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/** @protected */
|
|
132
|
-
ready() {
|
|
133
|
-
super.ready();
|
|
134
|
-
|
|
135
|
-
// By default, if the user hasn't provided a custom role,
|
|
136
|
-
// the role attribute is set to "button".
|
|
137
|
-
if (!this.hasAttribute('role')) {
|
|
138
|
-
this.setAttribute('role', 'button');
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Since the button component is designed on the base of the `[role=button]` attribute,
|
|
144
|
-
* and doesn't have a native <button> inside, in order to be fully accessible from the keyboard,
|
|
145
|
-
* it should manually fire the `click` event once an activation key is pressed,
|
|
146
|
-
* as it follows from the WAI-ARIA specifications:
|
|
147
|
-
* https://www.w3.org/TR/wai-aria-practices-1.1/#button
|
|
148
|
-
*
|
|
149
|
-
* According to the UI Events specifications,
|
|
150
|
-
* the `click` event should be fired exactly on `keydown`:
|
|
151
|
-
* https://www.w3.org/TR/uievents/#event-type-keydown
|
|
152
|
-
*
|
|
153
|
-
* @param {KeyboardEvent} event
|
|
154
|
-
* @protected
|
|
155
|
-
* @override
|
|
156
|
-
*/
|
|
157
|
-
_onKeyDown(event) {
|
|
158
|
-
super._onKeyDown(event);
|
|
159
|
-
|
|
160
|
-
if (this._activeKeys.includes(event.key)) {
|
|
161
|
-
event.preventDefault();
|
|
162
|
-
|
|
163
|
-
// `DisabledMixin` overrides the standard `click()` method
|
|
164
|
-
// so that it doesn't fire the `click` event when the element is disabled.
|
|
165
|
-
this.click();
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
110
|
}
|
|
169
111
|
|
|
170
112
|
customElements.define(Button.is, Button);
|