From f0fc0e90881c65868a91dbccb296eeafcca0ddae Mon Sep 17 00:00:00 2001 From: chenjiajian <770230504@qq.com> Date: Wed, 26 Apr 2023 17:28:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2=E5=BB=BA?= =?UTF-8?q?=E8=AE=AE=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/form/input.js | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/form/input.js b/src/form/input.js index af0498b..623ec2d 100644 --- a/src/form/input.js +++ b/src/form/input.js @@ -13,12 +13,12 @@ import { outsideClick } from '@bd/core' import '../icon/index.js' -import '../scroll/index.js' const ANIMATION = { duration: 100, custom: [{ transform: 'scaleY(0)' }, { transform: 'scaleY(1)' }] } + class Input extends Component { static props = { readOnly: false, @@ -43,6 +43,7 @@ class Input extends Component { #selectIndex = -1 #listShowing = false #stamp = 0 + static styles = [ css` :host { @@ -135,12 +136,10 @@ class Input extends Component { max-height: 200px; padding: 4px 0; border-radius: 4px; - // background: var(--color-plain-1); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15); transform-origin: top; - // transition: transform linear 00s; - // transform: scaleY(0); - wc-scroll { + + .scroller { max-height: 200px; } .list { @@ -173,7 +172,6 @@ class Input extends Component { .label input { padding: 0 10px; - // margin: 0 18px; } .label[prepend] input, @@ -394,7 +392,7 @@ class Input extends Component { ? html`` : html``}
- +
    ${this.#list.map( (li, idx) => @@ -406,7 +404,7 @@ class Input extends Component { ` )}
- +
` @@ -422,8 +420,8 @@ class Input extends Component { if (!this.#originList.length) { return } - if (!this.value) { - this.#list = this.#originList + if (!this.value.trim()) { + this.#list = [] } else { this.#list = this.#originList.filter(li => li.value.startsWith(this.value) @@ -442,16 +440,11 @@ class Input extends Component { return } this.#stamp = Date.now() + if (!this.#isComposing) { this.filterSuggestList() - this.$emit('fetch-suggest', { - value: this.value, - send: list => { - this.#originList = this.#list = list - this.$requestUpdate() - } - }) } + this.emitFetchSuggest() } handleClickItem(e) { let index = e.target.getAttribute('index') @@ -509,6 +502,15 @@ class Input extends Component { this.$requestUpdate() } } + emitFetchSuggest() { + this.$emit('fetch-suggest', { + value: this.value, + send: list => { + this.#originList = this.#list = list.slice(0, 5) + this.filterSuggestList() + } + }) + } handleFocus() { if (!this.#listShowing) { this.#listShowing = true