@vaadin/button 23.0.6 → 23.1.0-alpha3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vaadin/button",
3
- "version": "23.0.6",
3
+ "version": "23.1.0-alpha3",
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.0.6",
37
- "@vaadin/vaadin-lumo-styles": "^23.0.6",
38
- "@vaadin/vaadin-material-styles": "^23.0.6",
39
- "@vaadin/vaadin-themable-mixin": "^23.0.6"
37
+ "@vaadin/component-base": "23.1.0-alpha3",
38
+ "@vaadin/vaadin-lumo-styles": "23.1.0-alpha3",
39
+ "@vaadin/vaadin-material-styles": "23.1.0-alpha3",
40
+ "@vaadin/vaadin-themable-mixin": "23.1.0-alpha3"
40
41
  },
41
42
  "devDependencies": {
42
43
  "@esm-bundle/chai": "^4.3.4",
43
44
  "@vaadin/testing-helpers": "^0.3.2",
44
- "sinon": "^9.2.4"
45
+ "sinon": "^13.0.2"
45
46
  },
46
- "gitHead": "82ca8522e24a63343fb28bcb4c686e55d25c8858"
47
+ "gitHead": "8c9e64e8dfa158dd52a9bf6da351ff038c88ca85"
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
+ };
@@ -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 ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableMixin(HTMLElement))))) {}
38
+ declare class Button extends ButtonMixin(ElementMixin(ThemableMixin(HTMLElement))) {}
41
39
 
42
40
  declare global {
43
41
  interface HTMLElementTagNameMap {
@@ -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,31 +37,15 @@ 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 ActiveMixin
43
- * @mixes TabindexMixin
44
- * @mixes FocusMixin
40
+ * @mixes ButtonMixin
45
41
  * @mixes ElementMixin
46
42
  * @mixes ThemableMixin
47
43
  */
48
- class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableMixin(PolymerElement))))) {
44
+ class Button extends ButtonMixin(ElementMixin(ThemableMixin(PolymerElement))) {
49
45
  static get is() {
50
46
  return 'vaadin-button';
51
47
  }
52
48
 
53
- static get properties() {
54
- return {
55
- /**
56
- * Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
57
- *
58
- * @override
59
- * @protected
60
- */
61
- tabindex: {
62
- value: 0
63
- }
64
- };
65
- }
66
-
67
49
  static get template() {
68
50
  return html`
69
51
  <style>
@@ -99,10 +81,6 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM
99
81
  height: 100%;
100
82
  min-height: inherit;
101
83
  text-shadow: inherit;
102
- background: transparent;
103
- padding: 0;
104
- border: none;
105
- box-shadow: none;
106
84
  }
107
85
 
108
86
  [part='prefix'],
@@ -129,56 +107,6 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM
129
107
  </div>
130
108
  `;
131
109
  }
132
-
133
- /**
134
- * By default, `Space` is the only possible activation key for a focusable HTML element.
135
- * Nonetheless, the button is an exception as it can be also activated by pressing `Enter`.
136
- * See the "Keyboard Support" section in https://www.w3.org/TR/wai-aria-practices/examples/button/button.html.
137
- *
138
- * @protected
139
- * @override
140
- */
141
- get _activeKeys() {
142
- return ['Enter', ' '];
143
- }
144
-
145
- /** @protected */
146
- ready() {
147
- super.ready();
148
-
149
- // By default, if the user hasn't provided a custom role,
150
- // the role attribute is set to "button".
151
- if (!this.hasAttribute('role')) {
152
- this.setAttribute('role', 'button');
153
- }
154
- }
155
-
156
- /**
157
- * Since the button component is designed on the base of the `[role=button]` attribute,
158
- * and doesn't have a native <button> inside, in order to be fully accessible from the keyboard,
159
- * it should manually fire the `click` event once an activation key is pressed,
160
- * as it follows from the WAI-ARIA specifications:
161
- * https://www.w3.org/TR/wai-aria-practices-1.1/#button
162
- *
163
- * According to the UI Events specifications,
164
- * the `click` event should be fired exactly on `keydown`:
165
- * https://www.w3.org/TR/uievents/#event-type-keydown
166
- *
167
- * @param {KeyboardEvent} event
168
- * @protected
169
- * @override
170
- */
171
- _onKeyDown(event) {
172
- super._onKeyDown(event);
173
-
174
- if (this._activeKeys.includes(event.key)) {
175
- event.preventDefault();
176
-
177
- // `DisabledMixin` overrides the standard `click()` method
178
- // so that it doesn't fire the `click` event when the element is disabled.
179
- this.click();
180
- }
181
- }
182
110
  }
183
111
 
184
112
  customElements.define(Button.is, Button);