A
A
Aleksandr2018-06-20 14:23:51
Vue.js
Aleksandr, 2018-06-20 14:23:51

How to close select correctly?

How to properly close an open select when opening another?

<template>
      <div>
        <div class="vue-dropdown" :class="{'vue-active': toggle}">
            <span :class="{'el-icon-arrow-up' : toggle, 'el-icon-arrow-down' : !toggle}" @click="toggle = !toggle">{{ value.length ? value : defaultValue }}</span>
            <div class="vue-dropdown-collapsed" v-if="this.toggle">
                <input type="text" v-model="search" v-if="showSearch === 'true'" :placeholder="inputPlaceholder" @click="toggle == true">
                <ul>
                    <li v-for="(option, index) in options" :key="index" @click="update(option), selectedItem = option" v-if="option.name.toLowerCase().indexOf(search.toLowerCase()) !== -1">{{ option.name }}</li>
                </ul>
            </div>
        </div>
    </div>
</template>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Anton, 2018-06-20
@Sashjkeee

you can make a common event bus for all selects, subscribe to the discovery and set the state in the subscription. An example is here: https://habr.com/post/332628/

V
Vyacheslav Sobolev, 2018-06-22
@vrnehot

You can close select when clicking outside the component, and when pressing the tab key if it works as a transition between inputs in your components
https://www.npmjs.com/package/vue-click-outside

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question