This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

优化select组件;修复layer的报错

old
宇天 2019-08-13 20:35:05 +08:00
parent b61d4e7d90
commit 2bf6398486
2 changed files with 21 additions and 5 deletions

View File

@ -40,6 +40,7 @@ li {
input { input {
flex: 1; flex: 1;
width: auto;
min-width: 0; min-width: 0;
height: 100%; height: 100%;
padding: 0 5px; padding: 0 5px;
@ -344,7 +345,7 @@ export default class Select {
} }
// 触发列表选择 // 触发列表选择
_fetchSelect(idx, ev) { _fetchSelect(idx, needUpdateStyle) {
var item = this.props.LIST[idx] var item = this.props.LIST[idx]
this.value = item.value this.value = item.value
this.dispatchEvent( this.dispatchEvent(
@ -352,6 +353,21 @@ export default class Select {
detail: item 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.props.active = false
this.__OPTG__.classList.remove('show') this.__OPTG__.classList.remove('show')
} }
@ -402,8 +418,8 @@ export default class Select {
} }
// 回车触发select事件 // 回车触发select事件
if (ev.keyCode === 13) { if (ev.keyCode === 13) {
if (this.props.mvidx !== null) { if (this.props.mvidx !== null && this.props.active) {
return this._fetchSelect(this.props.mvidx, ev) return this._fetchSelect(this.props.mvidx)
} }
} }
}) })
@ -419,7 +435,7 @@ export default class Select {
// 选择选项 // 选择选项
this._handleSelect = bind(this.__OPTG__, 'click', ev => { this._handleSelect = bind(this.__OPTG__, 'click', ev => {
if (ev.target.tagName === 'DD' && !ev.target.hasAttribute('disabled')) { 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')) this.dispatchEvent(new CustomEvent('input'))
} }
}) })

View File

@ -482,7 +482,7 @@ class __layer__ {
layerDom[$id][1].classList.add('shift') layerDom[$id][1].classList.add('shift')
setTimeout(_ => { setTimeout(_ => {
$dom1.css(offsetStyle) $dom1.css(offsetStyle)
if (vm.$refs.input) { if (vm && vm.$refs.input) {
vm.$refs.input.focus() vm.$refs.input.focus()
} }
setTimeout(_ => { setTimeout(_ => {