Giter VIP home page Giter VIP logo

vue-cool-select's Introduction

Coverage Downloads Version License CircleCI Build Status Language grade: JavaScript codebeat badge codebeat badge Downloads Contributors

The current version is 3.x, if you are looking for 2.x, you can find it here (also, see breaking changes).

Features

  • no dependencies

  • props (30) allow you to customize a component in a various ways

  • slots (13) allow content to be changed anywhere

  • events (8) will let you know about everything

  • autocomplete (you can use custom search, you can also disable the search input)

  • keyboard controls (not only through the arrows)

  • support on mobile devices

  • validation, state of error and success

  • disabled and readonly

  • small and large sizes (as in bootstrap)

  • the ability to set your styles, you can write theme from scratch. 2 themes: Bootstrap 4 (equal styles), Material Design

  • TypeScript support

  • tab navigation

  • SSR (Server-Side Rendering)

  • auto determine the suitable position for the menu if it goes beyond the viewport

Write your suggestions, glad to add.

Installation

yarn add vue-cool-select or npm install --save vue-cool-select

Get started

NPM

  1. Import this plugin, css (theme) and add plugin via Vue.use:
import { CoolSelectPlugin } from 'vue-cool-select'

// paste the line below only if you need "bootstrap" theme
import 'vue-cool-select/dist/themes/bootstrap.css'
// paste the line below only if you need "material-design" theme
import 'vue-cool-select/dist/themes/material-design.css'
// you can also import your theme

Vue.use(CoolSelectPlugin)
  1. Use inside another component:
import { CoolSelect } from 'vue-cool-select'

export default {
  components: { CoolSelect },
  data () {
    return {
      // simple example of items
      items: ['Item 1', 'Item 2', 'Item 3'],
      // there will be a selected item
      selected: null
    }
  }
}
  1. Add to <template>:
<cool-select
  v-model="selected"
  :items="items"
/>

Browser (CDN)

Include vue-cool-select in the page.

<script src="https://unpkg.com/vue-cool-select"></script>

<!-- paste the line below only if you need "bootstrap" theme -->
<link rel="stylesheet" href="https://unpkg.com/vue-cool-select/dist/themes/bootstrap.css">
<!-- paste the line below only if you need "material-design" theme -->
<link rel="stylesheet" href="https://unpkg.com/vue-cool-select/dist/themes/material-design.css">

If Vue is detected in the Page, the plugin is installed automatically.


Documentation and examples here.

TODO

  • multi-select
  • 100% tests coverage

I am happy to add something or improve, you can write what you want to see. I also have more motivation to work if you give a star, thanks! 😄

vue-cool-select's People

Contributors

chypriote avatar danieldocki avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar greenkeeper[bot] avatar iliyazelenko avatar jwells967 avatar mariosh346 avatar samfeder avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-cool-select's Issues

An in-range update of @vue/test-utils is breaking the build 🚨

The devDependency @vue/test-utils was updated from 1.0.0-beta.29 to 1.0.0-beta.30.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@vue/test-utils is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Give ID to Input Element

Hi, it's me again!
So I want to change my cursor focus to another input with Enter key to speed up data input process.
Unfortunately, we cannot use el.nextElementSibling or el.nextSibling in BootstrapVue, since the input element placed within the <b-form-group>.
I think I can use ID to identify every input element within a form and jump from one to another input easily.
So, can you add one more props, say inputId, and pass it value to the ID attribute to the <input /> element?
Or maybe you have a better solution for this problem, let me know.
Thanks

An in-range update of rollup is breaking the build 🚨

The devDependency rollup was updated from 1.27.6 to 1.27.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

rollup is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for v1.27.7

2019-12-01

Bug Fixes

  • Fix a scenario where a reassignments to computed properties were not tracked (#3267)

Pull Requests

Commits

The new version differs by 4 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Need double TAB to get focus

Hi, thanks for this really nice component!
I found a little unexpected behavior here when I want to focus to this component from previous input control with Tab key. I need to stroke Tab key twice to focus and start typing on this component.
ezgif-1-27bc62878350
I have tested it on Chromium 73 and Firefox 66 on Ubuntu 16.04.
Thanks.

chrome autocomplete can't be disabled

would it be possible to include an override for the autocomplete property of the input control within the component?

it is always set to "off" and can't be overridden with :input-el-custom-attributes

my testing confirms this stack overflow answer that chrome no longer respects "off" to disable autocomplete, "new-password" must be used instead https://stackoverflow.com/a/55292734

I put in a pull request to just change the hardcoded value

Vue Select styling

Good day,

I'd like to know how a styling on this amazing component works.
I'd like to remove border and border-color and border-shadow from the select box

Thanks for quick reply

Errors in v.1.5.1 with Chrome and Firefox

Hi again, recently I updated your vue-cool-select to v. 1.5.1 and I found a cople errors.

Both errors happen when I use the disable-search prop.

In Firefox when I put two or three vue-cool-select, the second one displays drop-down options without close drop-down options at first select, see the next image.
imagen.

In Chrome doesn't select any option, only show options and close drop-down when release clic button.

If you need more details just ask for it. Thank you a lot for your component, best regards.

vue-cool-select scrolls the page automatically when clicking on the searchbar

Using vue-cool-select in different components
Whenever I click on the component it scrolls the page to put the component at the top.

using
"vue": "^2.5.22",
"vue-cool-select": "^1.6.2",

example of a problematic instance

 <cool-select
        v-model="userSelected"
        :items="userResults"
        :loading="searching"
         item-text="label"
         placeholder="Choose user"
        disable-filtering-by-search
         @search="onSearch">

         <template slot="no-data">{{noData ? "No Result." : "Two characters minimum." }}</template>
              <template slot="item" slot-scope="{item}">
                    <div>{{item.label}} - {{item.email}}</div>
         </template>
 </cool-select>

how to customize css?

This is an excellent component. Thank you for making it available.
How do I customize component css?
Is this possible?

Auto select the first item from the list

How can I select the first item in the list?

It is more practical for the user to type what he is looking for and then hit enter if the item he is looking for is the first one on the list.

Typescript - missing some types in vue-cool-select/types/types.d.ts

Low priority - it throws errors messages in the compiler but everything still works fine.
Version 3.0.2

Specific messages are:
Parameters implicitly have 'any' type:
Line 9, 10, 11, 41 through 48
Functions lack return-type annotation, implicitly have 'any' return type:
Line 41 through 48

how to clear input box?

Thanks for this great tool.

How I can remove the selected values?
I am using ajax options and I can set selected to null again and items to [] but the entered text is always there even after setting these changes., How I can clear the text and only show the placeholder?

able to only limited results

Hi
i have try to implement infinite scroll with search using this. but some how i am able to see only 20 results. but the i have lot of data .

How to add two cool-select (data filled with rest API) component on one component.

I want to add two cool-select data filled with API on one component.

<cool-select
            v-model="selected"
            :items="items"
            :loading="loading"
            item-text="name"
            :placeholder="gettext('Enter company name')"
          
            @search="onSearch"
            style="position:relative; padding:0 0 0 0;"
          >
            <template #no-data>
              <div class="item  ">
                {{
              noData
                ? gettext('No company found.')
                : gettext('Type at least 3 letters to search.')
            }}
              </div>
            </template>
            <template #item="{ item }">
              <div class="item">
                <span class="item-name"> {{ item.name }} </span>
              </div>
            </template>
          </cool-select>
          <cool-select
            v-model="selected2"
            :items="items"
            :loading="loading"
            item-text="name"
            :placeholder="gettext('Enter company name')"
            :search-text.sync="search"
            @search="onSearch"
            style="position:relative; padding:0 0 0 0;"
          >
            <template #no-data>
              <div class="item  ">
                {{
              noData
                ? gettext('No company found.')
                : gettext('Type at least 3 letters to search.')
            }}
              </div>
            </template>
            <template #item="{ item }">
              <div class="item">
                <span class="item-name"> {{ item.name }} </span>
              </div>
            </template>
          </cool-select>

Initial value for the component (search)

Hi, it's me again.
So I create separated component to simplify the input of a field in a table, and include that component to my form. And add v-model support to that component.
But sometime we need to edit a row using the same form. As usual, an edit form will contain the initial value from a database. But I found that I am unable to set an initial value for this component.
Here is the code I use:

CodeSanbox

Can we have a solution for this problem?
CMIIW
Thanks

Dropdown Closing Issue

just installed this component and it works great, so thanks for that. One thing i did notice is that if you're using the item slot setup (with images) when the dropdown disappears, the images stay visible a split second longer than the actual dropdown. doesn't effect functionality, just looks a bit odd when it's disappearing.

Dropup position when falling out of container or page

When I have a select on the bottom of my page, the dropdown menu increases the page height instead of displaying it above the input. See the gif below for a quick example:

vue-cool-select-bottom-of-page-dropdown

Is there a simple solution for this to apply myself, or does it require editing the package?

Thanks for this amazing package, there is currently no better one!

The roller can't scroll to the right position when use keyboard arrow keys to select items

Hello people,

When I use keyboard arrow keys to select items, the roller can't scroll to the right position.

image

And I got the solution, but it will be great if someone can help me to fix this bug.
Thanks.

<template>
    <div :class="className">
        <CoolSelect @search="onSearch"
                    @select="select($event)"
                    @blur="blur"
                    @keyup="moveScroll($event)"
                    :items="items"
                    :item-text="itemText"
                    :item-value="itemValue"
                    :placeholder="placeholder"
                    :ref="relName"
                    disable-filtering-by-search
        >

            <template slot="no-data">
                <slot name="c-no-data"></slot>
            </template>

            <template slot="item" slot-scope="{ item }">
                <slot name="c-item" v-bind:item="item"></slot>
            </template>

        </CoolSelect>
    </div>
</template>

<script>
    import { CoolSelect } from 'vue-cool-select';

    export default {
        props: {
            className: {
                type: String,
                default: 'cool-select-c'
            },
            search: {
                type: Function,
                default: function() {}
            },
            select: {
                type: Function,
                default($event) {}
            },
            blur: {
                type: Function,
                default: function() {}
            },
            items: {
                type: Array,
                default: []
            },
            searchText: {
                type: String,
                default: ''
            },
            itemText: {
                type: String,
                default: 'name'
            },
            itemValue: {
                type: String,
                default: 'name'
            },
            placeholder: {
                type: String,
                default: ''
            },
            maxHeight: {
                type: Number,
                default: 300
            },
        },
        components: {
            CoolSelect,
        },
        data() {
            return {
                relName: 'cSelect',
                keyDownCount: 0,
            };
        },
        watch: {
            searchText: function (newValue, oldValue) {
                this.$refs['cSelect'].setSearchData(newValue);
                return newValue;
            },
        },
        methods: {
            moveScroll(event) {
                if (this.items.length > 0 && ((event.keyCode === 40) || (event.keyCode === 38))) {
                    this.keyDownCount = (event.keyCode === 40) ? ++this.keyDownCount : this.keyDownCount;
                    this.keyDownCount = (event.keyCode === 38) ? --this.keyDownCount : this.keyDownCount;

                    this.keyDownCount = (this.keyDownCount > this.items.length) ? 1 : this.keyDownCount;
                    this.keyDownCount = (this.keyDownCount === 0) ? this.items.length : this.keyDownCount;

                    console.log(this.keyDownCount);
                    if ((this.keyDownCount >= 10) && (this.keyDownCount <= this.items.length)) {
                        this.$refs[this.relName].$el.querySelector('.IZ-select__menu--at-bottom .IZ-select__menu-items').scrollTop += this.maxHeight;
                        this.$refs[this.relName].$el.querySelector('.IZ-select__menu--at-top .IZ-select__menu-items').scrollTop += this.maxHeight;

                    } else {
                        this.$refs[this.relName].$el.querySelector('.IZ-select__menu--at-bottom .IZ-select__menu-items').scrollTop = 0;
                        this.$refs[this.relName].$el.querySelector('.IZ-select__menu--at-top .IZ-select__menu-items').scrollTop = 0;
                    }
                }
            },
            onSearch(search) {
                this.keyDownCount = 0;
                this.search(search);
            }
        }
    }
</script>

Spellcheck attribute support

Our list has many technical words that produce red spellchecker underlines on the text input. Would it be possible to add an option that puts spellcheck="false" onto the input element? As we have no way of disabling this from our side right now.

Style is not applied

I am using this control on following the examles but there's no style :(

image

Can you help me? thanks!

An in-range update of @vue/cli-service is breaking the build 🚨

The devDependency @vue/cli-service was updated from 3.5.2 to 3.5.3.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

@vue/cli-service is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Commits

The new version differs by 6 commits.

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Pressing enter key to select item submits form

When I press the enter key to select an item the form gets submitted, this differs from the behaviour of the built in browser select. Is there a way to change this behaviour? Maybe block this event from getting through somehow.

Thanks, great component!

[ERROR] Cannot mount component

Error message: template or render function not defined.

import VueCoolInput from 'vue-cool-select';

Vue.use(VueCoolInput);

Vue.component('cool-input', VueCoolInput);

Addition for async causes CSP errors

Our application has Content Security Policies that doesn't allow dynamically defining functions.

Recently added async modifier to the showMenu function causes the inclussion of the regenerator polyfill by rollup. In this package there is a function that is dynamic

HTML5 "required" attribute as prop

Issue #190 explains a workaround by using input-el-custom-attributes. I think required is simple/common enough that it deserves its own prop. Thoughts?

Proposed usage:

<CoolSelect required />

Versus the current:

<CoolSelect input-el-custom-attributes="{required:true}" />

getItemValue's wrong logic if argument is zero

Hello I probably encountered an issue with your getItemValue function:

    getItemValue (item) {
      if (!item) return null
      if (this.itemValue) return item[this.itemValue]
      if (isObject(item)) {
        const keys = Object.keys(item)
        if (keys.length === 1) {
          return item[keys[0]]
        }
        return item
      }
      return item
    },

the first line is prone to errors in case the "0" (zero) is passed. suggest to change this to lodash isNil check

Retain the text entered if we click outside the search box

Hi,

Im using the version : "vue-cool-select": "^3.5.1"

How to make the search box act like a normal text field, even if we didn't select any search list option.

Currently when you click outside the search box the text entered in the field is getting reset.

Scrolls to top when select is far down page

Firstly - great work on this.

I have a small problem on mobile devices and mobile responsive view in the browser.

My cool-select is quite far down on a large form. When I focus on the select component, or start typing, it causes the browser to scroll to the top of the page.

<div class="col-6">
<cool-select
                      v-model="form.chosen_dog"
                      :items="animals"
                      itemText="name"
                      itemValue="id"
                    >
                      <template slot="selection" slot-scope="{ item: animal }">
                        <div class="d-flex flex-row">
                          <img :src="animal.image" :alt="animal.name" width="30" height="30" 
                          class="mr-3" />
                          <span>{{ animal.name }}</span>
                        </div>
                      </template>

                      <template slot="item" slot-scope="{ item: animal }">
                        <div class="d-flex flex-row justify-content-between">
                          <span>{{ animal.name }}</span>
                          <img :src="animal.image" :alt="animal.name" width="30" height="30" class="align-self-end" />
                        </div>
                      </template>
                    </cool-select>
</div>

UPDATE:

It seems to happen when using the 'bootstrap' theme and the component is inside bootstrap's col-xx elements.

See this Codesandbox for modified version of the demo that shows the issue. Make sure you view it on a phone or in responsive mode on desktop browser: https://codesandbox.io/s/81zro028z2

position prop

Would you consider adding a new position prop to change the select position depending on the current scroll position?

Maybe something like this:

position: [ 'auto', 'above', 'below' ]

Thank your for this plugin.

HTML 5 required input

would it be possible to include an option to use built in html 5 input required property to control validation rather than using the combination of successful and error-message

no-data generates [Vue warn]: Error in render: "TypeError: Cannot read property 'options' of undefined"

I am getting the above vue warning as soon as I type in a set of characters that produce no data from my data set. I assume this is something to do with my local dev installation as the demo works perfectly. I assume that the problem is that $coolSelect is not available, i.e. from component.vue

<slot name="no-data"> {{ $coolSelect.options.text.noData }} </slot>

and $coolSelect is imported from main.js

For some reason I get a console warning rather than the 'No data available' message. No error is thrown so the application continues OK.

I tried installing with yarn and npm but it made no difference. Do you have any idea what I have done wrong?

An in-range update of core-js is breaking the build 🚨

The devDependency core-js was updated from 3.4.6 to 3.4.7.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

core-js is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ci/circleci: build: Your tests failed on CircleCI (Details).

Release Notes for 3.4.7 - 2019.12.03
  • Fixed an NPM publishing issue
FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

IE11 - Clicking anything other than the vue-cool-select or another vue-cool-select component fires something unwanted

v3.5.1

In the following examples I have a cool-select inside a dropdown component. This dropdown component should be kept open until the user clicks outside of it, or the trigger button itself. It shouldn't dismiss when a user still clicks inside (for ex. an Apply button) the dropdown component. As you can see in the Chrome example is how it is supposed to work.

IE11 (don't mind the weird animation)

ie11-dropdown-cool-select-dismiss

Chrome

chrome-dropdown-cool-select-dismiss

Disable options

Hello,
Is it possible to make options disabled, so the user can't click them? Like the "disabled" attribute for options in a html select.
We'd like to show the availability of tickets in the cool-select. Sold out options should not be selectable but still be visible. Right now we added a css class to the option text to show it in a different color, but it would be really nice if we could disable these options entirely to prevent the user from selecting them.

Great component btw :)

Blurring the component after onSelect

Loving the component so far, and using it on my current project. However, there is a feature that I would like you to add and that seems fit for this component. It would be great to have a prop to invoke blur after selecting an item, or to be able to emit blur inside the select event.

I tried doing this by emitting blur inside the select event handler as in
onSelect (item) { console.log('select', this.$refs.coolselect) this.$refs.coolselect.$emit('blur'); }

also tried
onSelect (item) { this.$refs.coolselect.wishShowMenu = false; this.$refs.coolselect.focused = false; }

however niether work, also tried setting a timeout, that doesn't work either. If you have another option that I could try, please let me know. I did not try emitting blur outside the onSelect listener but I believe that I should be allowed to blur it inside.

the component is awesome I hope that you'll add this feature soon

Get list from JSON Array

Hello and thanks for the cool select,

but i was wondering if is there a way to give the select a json array like this :
[{"first_name":"lati"},{"first_name":"wassel"} ... ]

Or do i have to parse it (JSON.parse) before ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.