66import '@vaadin/progress-bar/src/vaadin-progress-bar.js' ;
77import './vaadin-upload-icons.js' ;
88import { html , PolymerElement } from '@polymer/polymer/polymer-element.js' ;
9+ import { FocusMixin } from '@vaadin/component-base/src/focus-mixin.js' ;
910import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js' ;
1011
1112/**
@@ -15,36 +16,40 @@ import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mix
1516 *
1617 * The following shadow DOM parts are available for styling:
1718 *
18- * Part name | Description
19- * ---| ---
20- * `row` | File container
21- * `info` | Container for file status icon, file name, status and error messages
22- * `done-icon` | File done status icon
23- * `warning-icon` | File warning status icon
24- * `meta` | Container for file name, status and error messages
25- * `name` | File name
26- * `error` | Error message, shown when error happens
27- * `status` | Status message
28- * `commands` | Container for file command icons
29- * `start-button` | Start file upload button
30- * `retry-button` | Retry file upload button
31- * `remove-button` | Remove file button
32- * `progress`| Progress bar
19+ * Part name | Description
20+ * -----------------|---------- ---
21+ * `row` | File container
22+ * `info` | Container for file status icon, file name, status and error messages
23+ * `done-icon` | File done status icon
24+ * `warning-icon` | File warning status icon
25+ * `meta` | Container for file name, status and error messages
26+ * `name` | File name
27+ * `error` | Error message, shown when error happens
28+ * `status` | Status message
29+ * `commands` | Container for file command buttons
30+ * `start-button` | Start file upload button
31+ * `retry-button` | Retry file upload button
32+ * `remove-button` | Remove file button
33+ * `progress` | Progress bar
3334 *
3435 * The following state attributes are available for styling:
3536 *
36- * Attribute | Description | Part name
37- * ---|---|---
38- * `error` | An error has happened during uploading | `:host`
39- * `indeterminate` | Uploading is in progress, but the progress value is unknown | `:host`
40- * `uploading` | Uploading is in progress | `:host`
41- * `complete` | Uploading has finished successfully | `:host`
37+ * Attribute | Description
38+ * -----------------|-------------
39+ * `focus-ring` | Set when the element is focused using the keyboard.
40+ * `focused` | Set when the element is focused.
41+ * `error` | An error has happened during uploading.
42+ * `indeterminate` | Uploading is in progress, but the progress value is unknown.
43+ * `uploading` | Uploading is in progress.
44+ * `complete` | Uploading has finished successfully.
4245 *
4346 * See [Styling Components](https://vaadin.com/docs/latest/ds/customization/styling-components) documentation.
4447 *
48+ * @extends HTMLElement
49+ * @mixes FocusMixin
4550 * @mixes ThemableMixin
4651 */
47- class UploadFile extends ThemableMixin ( PolymerElement ) {
52+ class UploadFile extends FocusMixin ( ThemableMixin ( PolymerElement ) ) {
4853 static get template ( ) {
4954 return html `
5055 < style >
@@ -129,7 +134,17 @@ class UploadFile extends ThemableMixin(PolymerElement) {
129134 return {
130135 file : Object ,
131136
132- i18n : Object
137+ i18n : Object ,
138+
139+ /**
140+ * Indicates whether the element can be focused and where it participates in sequential keyboard navigation.
141+ * @protected
142+ */
143+ tabindex : {
144+ type : Number ,
145+ value : 0 ,
146+ reflectToAttribute : true
147+ }
133148 } ;
134149 }
135150
@@ -143,6 +158,38 @@ class UploadFile extends ThemableMixin(PolymerElement) {
143158 ] ;
144159 }
145160
161+ /** @protected */
162+ ready ( ) {
163+ super . ready ( ) ;
164+
165+ // Handle moving focus to the button on Tab.
166+ this . shadowRoot . addEventListener ( 'focusin' , ( e ) => {
167+ const target = e . composedPath ( ) [ 0 ] ;
168+
169+ if ( target . getAttribute ( 'part' ) . endsWith ( 'button' ) ) {
170+ this . _setFocused ( false ) ;
171+ }
172+ } ) ;
173+
174+ // Handle moving focus from the button on Shift Tab.
175+ this . shadowRoot . addEventListener ( 'focusout' , ( e ) => {
176+ if ( e . relatedTarget === this ) {
177+ this . _setFocused ( true ) ;
178+ }
179+ } ) ;
180+ }
181+
182+ /**
183+ * Override method inherited from `FocusMixin` to mark the file as focused
184+ * only when the host is focused.
185+ * @param {Event } event
186+ * @return {boolean }
187+ * @protected
188+ */
189+ _shouldSetFocus ( event ) {
190+ return event . composedPath ( ) [ 0 ] === this ;
191+ }
192+
146193 /** @private */
147194 _fileAborted ( abort ) {
148195 if ( abort ) {
0 commit comments