From 657f9b9c3a48408c2d0d1688b3f9cae0a01d60c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=A5=95?= Date: Sun, 4 Mar 2018 11:16:06 +0800 Subject: [PATCH] Popover & Tooltip: focus reference element on tab if it's focusable (#9990) --- packages/popover/src/main.vue | 8 +++++++- packages/tooltip/src/main.js | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/popover/src/main.vue b/packages/popover/src/main.vue index 4c6daf24f..8b5630f11 100644 --- a/packages/popover/src/main.vue +++ b/packages/popover/src/main.vue @@ -84,7 +84,13 @@ export default { popper.setAttribute('tabindex', 0); if (this.trigger !== 'click') { - on(reference, 'focusin', this.handleFocus); + on(reference, 'focusin', () => { + this.handleFocus(); + const instance = reference.__vue__; + if (instance && instance.focus) { + instance.focus(); + } + }); on(popper, 'focusin', this.handleFocus); on(reference, 'focusout', this.handleBlur); on(popper, 'focusout', this.handleBlur); diff --git a/packages/tooltip/src/main.js b/packages/tooltip/src/main.js index 2a02109ce..ca43931f3 100644 --- a/packages/tooltip/src/main.js +++ b/packages/tooltip/src/main.js @@ -117,7 +117,18 @@ export default { this.$el.setAttribute('tabindex', 0); on(this.referenceElm, 'mouseenter', this.show); on(this.referenceElm, 'mouseleave', this.hide); - on(this.referenceElm, 'focus', this.handleFocus); + on(this.referenceElm, 'focus', () => { + if (!this.$slots.default || !this.$slots.default.length) { + this.handleFocus(); + return; + } + const instance = this.$slots.default[0].componentInstance; + if (instance && instance.focus) { + instance.focus(); + } else { + this.handleFocus(); + } + }); on(this.referenceElm, 'blur', this.handleBlur); on(this.referenceElm, 'click', this.removeFocusing); }