Giter Club home page Giter Club logo

vue-dropdown's Introduction

vue-dynamic-dropdown

A Highly Customizable, easy-to-use, elegant, dropdown component

Feedback would be much appreciated, questions, suggestions, issues are more than welcome.

MIT License view on npm

Demo

A dropdown demo gif

Edit Vue Dynamic Dropdown Component

Usage:

First

Install via NPM npm i vue-dynamic-dropdown

Second

Require in your project:

var VueDropdown = require('vue-dynamic-dropdown');

or ES6 syntax:

import VueDropdown from 'vue-dynamic-dropdown'

Third

You can register the component globally:

Vue.component('vue-dropdown', VueDropdown);

Or locally in a single Vue component:

components: {
  VueDropdown
}

Insert the following selector anywhere in your project (global) or in your existing component (local): NOTE: To get up and running quickly the package now supports rendering just the selector with default values.

<vue-dropdown></vue-dropdown>

Docs:

config: {...} is a configuration object that is to be bound to vue-dropdown, API properties are:

Basics

Property Type Description
options array Holds the inner selection options of the dropdown (shown when open), each single option is an object that has the value key that pairs with the given value e.g { value: '1st Option' }
width number Determines the width of the dropdown button & options drawer
placeholder string The text shown on the dropdown button by default
prefix string A text prefix that will be added before the placeholder text
disabled boolean Set true if the dropdown should be disabled

Customized Styling

Property Type Description
backgroundColor string Set the dropdown button & options area background color
hoverBackgroundColor string Set the dropdown button & options hover background color
border string Set the dropdown button & options border
textColor string Set the dropdown button & options text color
disabledBackgroundColor string Set the disabled dropdown button background color
disabledTextColor string Set the disabled dropdown button text color

Events

Event Name Returns Description
setSelectedOption Option Object Clicking a dropdown option emits an option data object upwards

Listening to the event e.g:

<vue-dropdown @setSelectedOption="myLocalSetterFunction($event)"></vue-dropdown>

Implementation Example

Define your config options object in the component importing VueDropdown e.g

data: function() {
    return {
        config: {
            options: [
                {
                    value: "option 1"
                },
                {
                    value: "option 2"
                },
                {
                    value: "option 3"
                },
            ],
            prefix: "The",
            backgroundColor: "green", 
            disabled: false,
        }
    }
}

And bind it to the selector like so

<vue-dropdown :config="config"></vue-dropdown>

๐Ÿ‘จโ€๐Ÿ’ป Follow me on Twitter.

Donation

If this project helped you reduce development time, you can buy me a cup of coffee :)

vue-dropdown's People

Contributors

awatea avatar jonathandn avatar karnthis 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

Watchers

 avatar  avatar

vue-dropdown's Issues

Package does not work with baseline CLI Vue App

The Package gives compile errors when following install/getting started directions as written. The following are prerequisites due to use of SASS:

  • sass-loader
  • node-sass
  • style-loader

Compile was successful for me after dev saving the above. Please add these as listed prereqs, or add to the install. I can submit a PR for the above if desired.

Event listener never removed leads to memory leak

The "resize" listener added on window here:

window.addEventListener("resize", calcHeight);

is never removed. It leads to memory leak.
Also I think you should not use a directive here. Because you cannot retain a reference to the closure calcHeight() in the directive, so you won't be able to remove the listener afterwards.

Options value are not being displayed because `option` and `i` are inverted

Found out that options weren't being displayed because in the v-for loop, option and i are in the wrong order.
That is the correct order :

<div v-expand="isExpanded" class="options expand">
	<div
		v-for="(option, i) in configOptions"
		:key="'option-' + i"
		class="option"
		@click="setCurrentSelectedOption(option);"
	>
		{{ option.value }}
	</div>
</div>

You may need an appropriate loader

Failed to compile. ./node_modules/vue-dynamic-dropdown/dropdown.vue 1:0 Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type.
> <template> | <div | class="dropdown"

How to solve this issue? Thanks a lot!

Support disabled option

From the basic feature to advance. Disabled option is basic feature option HTML5. You need it first after go to advance feature. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

File to import not found or unreadable: ./vue-dropdown

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):

	@import "./vue-dropdown";
^
      File to import not found or unreadable: ./vue-dropdown.
      in /PROJECTFOLDER/node_modules/vue-dynamic-dropdown/dropdown.vue (line 152, column 1)

Cannot find stylesheet to import

You're trying to import the 'vue-dropdown' stylesheet but that doesn't exist.
You did fix this in a recent commit by changing the import to 'dropdown' but changed it back to 'vue-dropdown' in the commit after that

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.