|
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> |
@@ -125,56 +107,6 @@ class Button extends ActiveMixin(TabindexMixin(FocusMixin(ElementMixin(ThemableM |
125 | 107 | </div> |
126 | 108 | `; |
127 | 109 | } |
128 | | - |
129 | | - /** |
130 | | - * By default, `Space` is the only possible activation key for a focusable HTML element. |
131 | | - * Nonetheless, the button is an exception as it can be also activated by pressing `Enter`. |
132 | | - * See the "Keyboard Support" section in https://www.w3.org/TR/wai-aria-practices/examples/button/button.html. |
133 | | - * |
134 | | - * @protected |
135 | | - * @override |
136 | | - */ |
137 | | - get _activeKeys() { |
138 | | - return ['Enter', ' ']; |
139 | | - } |
140 | | - |
141 | | - /** @protected */ |
142 | | - ready() { |
143 | | - super.ready(); |
144 | | - |
145 | | - // By default, if the user hasn't provided a custom role, |
146 | | - // the role attribute is set to "button". |
147 | | - if (!this.hasAttribute('role')) { |
148 | | - this.setAttribute('role', 'button'); |
149 | | - } |
150 | | - } |
151 | | - |
152 | | - /** |
153 | | - * Since the button component is designed on the base of the `[role=button]` attribute, |
154 | | - * and doesn't have a native <button> inside, in order to be fully accessible from the keyboard, |
155 | | - * it should manually fire the `click` event once an activation key is pressed, |
156 | | - * as it follows from the WAI-ARIA specifications: |
157 | | - * https://www.w3.org/TR/wai-aria-practices-1.1/#button |
158 | | - * |
159 | | - * According to the UI Events specifications, |
160 | | - * the `click` event should be fired exactly on `keydown`: |
161 | | - * https://www.w3.org/TR/uievents/#event-type-keydown |
162 | | - * |
163 | | - * @param {KeyboardEvent} event |
164 | | - * @protected |
165 | | - * @override |
166 | | - */ |
167 | | - _onKeyDown(event) { |
168 | | - super._onKeyDown(event); |
169 | | - |
170 | | - if (this._activeKeys.includes(event.key)) { |
171 | | - event.preventDefault(); |
172 | | - |
173 | | - // `DisabledMixin` overrides the standard `click()` method |
174 | | - // so that it doesn't fire the `click` event when the element is disabled. |
175 | | - this.click(); |
176 | | - } |
177 | | - } |
178 | 110 | } |
179 | 111 |
|
180 | 112 | customElements.define(Button.is, Button); |
|
0 commit comments