From 48fda08795b2ce7fed9262cbc4a917fb43311d89 Mon Sep 17 00:00:00 2001 From: tangjinzhou Date: Fri, 27 Sep 2019 18:44:11 +0800 Subject: [PATCH 1/2] fix: ie select open bug #1223 --- components/_util/env.js | 9 +++++++++ components/vc-select/Select.jsx | 5 ++++- components/vc-trigger/Trigger.jsx | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/components/_util/env.js b/components/_util/env.js index 6a58df2b9..b4d3769a7 100644 --- a/components/_util/env.js +++ b/components/_util/env.js @@ -1,4 +1,13 @@ +// Browser environment sniffing export const inBrowser = typeof window !== 'undefined'; +export const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform; +export const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase(); export const UA = inBrowser && window.navigator.userAgent.toLowerCase(); export const isIE = UA && /msie|trident/.test(UA); export const isIE9 = UA && UA.indexOf('msie 9.0') > 0; +export const isEdge = UA && UA.indexOf('edge/') > 0; +export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android'); +export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios'); +export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; +export const isPhantomJS = UA && /phantomjs/.test(UA); +export const isFF = UA && UA.match(/firefox\/(\d+)/); diff --git a/components/vc-select/Select.jsx b/components/vc-select/Select.jsx index 94ee4c85a..5e84c1eff 100644 --- a/components/vc-select/Select.jsx +++ b/components/vc-select/Select.jsx @@ -449,6 +449,7 @@ const Select = { onArrowClick(e) { e.stopPropagation(); e.preventDefault(); + this.clearBlurTime(); if (!this.disabled) { this.setOpenState(!this.$data._open, !this.$data._open); } @@ -623,6 +624,7 @@ const Select = { inputBlur(e) { const target = e.relatedTarget || document.activeElement; if ( + e.relatedTarget === this.$refs.arrow || (target && this.selectTriggerRef && this.selectTriggerRef.getInnerMenu() && @@ -685,7 +687,7 @@ const Select = { } this.setOpenState(false); this.$emit('blur', this.getVLForOnChange(value)); - }, 10); + }, 200); }, inputFocus(e) { if (this.$props.disabled) { @@ -1412,6 +1414,7 @@ const Select = { style={UNSELECTABLE_STYLE} {...{ attrs: UNSELECTABLE_ATTRIBUTE }} onClick={this.onArrowClick} + ref="arrow" > {inputIcon || defaultIcon} diff --git a/components/vc-trigger/Trigger.jsx b/components/vc-trigger/Trigger.jsx index 1d75f7892..490bb7faf 100644 --- a/components/vc-trigger/Trigger.jsx +++ b/components/vc-trigger/Trigger.jsx @@ -237,7 +237,7 @@ export default { }, onBlur(e) { - if (!contains(e.target, e.relatedTarget)) { + if (!contains(e.target, e.relatedTarget || document.activeElement)) { this.fireEvents('blur', e); this.clearDelayTimer(); if (this.isBlurToHide()) { From 6dd61cdb76926f14de89e894dc7f1f21ef864a5e Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sat, 28 Sep 2019 18:00:24 +0800 Subject: [PATCH 2/2] style: format code --- components/_util/env.js | 4 ++-- components/vc-select/Select.jsx | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/components/_util/env.js b/components/_util/env.js index b4d3769a7..96894fc58 100644 --- a/components/_util/env.js +++ b/components/_util/env.js @@ -6,8 +6,8 @@ export const UA = inBrowser && window.navigator.userAgent.toLowerCase(); export const isIE = UA && /msie|trident/.test(UA); export const isIE9 = UA && UA.indexOf('msie 9.0') > 0; export const isEdge = UA && UA.indexOf('edge/') > 0; -export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android'); -export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios'); +export const isAndroid = (UA && UA.indexOf('android') > 0) || weexPlatform === 'android'; +export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || weexPlatform === 'ios'; export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge; export const isPhantomJS = UA && /phantomjs/.test(UA); export const isFF = UA && UA.match(/firefox\/(\d+)/); diff --git a/components/vc-select/Select.jsx b/components/vc-select/Select.jsx index 5e84c1eff..028f79ebf 100644 --- a/components/vc-select/Select.jsx +++ b/components/vc-select/Select.jsx @@ -51,6 +51,7 @@ import { } from './util'; import { SelectPropTypes } from './PropTypes'; import contains from '../_util/Dom/contains'; +import { isIE, isEdge } from '../_util/env'; Vue.use(ref, { name: 'ant-ref' }); const SELECT_EMPTY_VALUE_KEY = 'RC_SELECT_EMPTY_VALUE_KEY'; @@ -623,13 +624,17 @@ const Select = { }, inputBlur(e) { const target = e.relatedTarget || document.activeElement; + + // https://github.com/vueComponent/ant-design-vue/issues/999 + // https://github.com/vueComponent/ant-design-vue/issues/1223 if ( - e.relatedTarget === this.$refs.arrow || - (target && - this.selectTriggerRef && - this.selectTriggerRef.getInnerMenu() && - this.selectTriggerRef.getInnerMenu().$el === target) || - contains(e.target, target) + (isIE || isEdge) && + (e.relatedTarget === this.$refs.arrow || + (target && + this.selectTriggerRef && + this.selectTriggerRef.getInnerMenu() && + this.selectTriggerRef.getInnerMenu().$el === target) || + contains(e.target, target)) ) { e.target.focus(); e.preventDefault();