From 2bf63984861984cfbc1495c6ab8045de179afd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Tue, 13 Aug 2019 20:35:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96select=E7=BB=84=E4=BB=B6;?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dlayer=E7=9A=84=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/select.wc | 24 ++++++++++++++++++++---- src/layer/index.js | 2 +- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/form/select.wc b/src/form/select.wc index b4f5ff8..a29bfd9 100644 --- a/src/form/select.wc +++ b/src/form/select.wc @@ -40,6 +40,7 @@ li { input { flex: 1; + width: auto; min-width: 0; height: 100%; padding: 0 5px; @@ -344,7 +345,7 @@ export default class Select { } // 触发列表选择 - _fetchSelect(idx, ev) { + _fetchSelect(idx, needUpdateStyle) { var item = this.props.LIST[idx] this.value = item.value this.dispatchEvent( @@ -352,6 +353,21 @@ export default class Select { detail: item }) ) + if (needUpdateStyle) { + this.props.mvidx = idx + var items = Array.from( + this.__OPTG__.firstElementChild.firstElementChild.children + ).filter(it => { + return it.tagName === 'DD' && !it.hasAttribute('disabled') + }) + items.forEach((it, i) => { + if (i === idx) { + it.setAttribute('focus', '') + } else { + it.removeAttribute('focus') + } + }) + } this.props.active = false this.__OPTG__.classList.remove('show') } @@ -402,8 +418,8 @@ export default class Select { } // 回车触发select事件 if (ev.keyCode === 13) { - if (this.props.mvidx !== null) { - return this._fetchSelect(this.props.mvidx, ev) + if (this.props.mvidx !== null && this.props.active) { + return this._fetchSelect(this.props.mvidx) } } }) @@ -419,7 +435,7 @@ export default class Select { // 选择选项 this._handleSelect = bind(this.__OPTG__, 'click', ev => { if (ev.target.tagName === 'DD' && !ev.target.hasAttribute('disabled')) { - this._fetchSelect(ev.target.dataset.idx, ev) + this._fetchSelect(+ev.target.dataset.idx, true) this.dispatchEvent(new CustomEvent('input')) } }) diff --git a/src/layer/index.js b/src/layer/index.js index 9fa3e61..5402266 100644 --- a/src/layer/index.js +++ b/src/layer/index.js @@ -482,7 +482,7 @@ class __layer__ { layerDom[$id][1].classList.add('shift') setTimeout(_ => { $dom1.css(offsetStyle) - if (vm.$refs.input) { + if (vm && vm.$refs.input) { vm.$refs.input.focus() } setTimeout(_ => {