{"id":20548231,"url":"https://github.com/robrogers3/vue-single-select","last_synced_at":"2025-04-14T10:52:42.011Z","repository":{"id":32755194,"uuid":"141664855","full_name":"robrogers3/vue-single-select","owner":"robrogers3","description":"single select dropdown with autocomplete","archived":false,"fork":false,"pushed_at":"2022-12-08T16:58:05.000Z","size":4481,"stargazers_count":45,"open_issues_count":37,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-28T00:06:32.771Z","etag":null,"topics":["autocomplete","chosen","component","dropdown","javascript","select","typeahead","vue","vue-component"],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robrogers3.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-20T04:49:44.000Z","updated_at":"2023-12-01T07:12:20.000Z","dependencies_parsed_at":"2023-01-14T22:15:30.516Z","dependency_job_id":null,"html_url":"https://github.com/robrogers3/vue-single-select","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Fvue-single-select","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Fvue-single-select/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Fvue-single-select/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robrogers3%2Fvue-single-select/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robrogers3","download_url":"https://codeload.github.com/robrogers3/vue-single-select/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868808,"owners_count":21174755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autocomplete","chosen","component","dropdown","javascript","select","typeahead","vue","vue-component"],"created_at":"2024-11-16T02:12:40.282Z","updated_at":"2025-04-14T10:52:41.989Z","avatar_url":"https://github.com/robrogers3.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vue-single-select\n\n    simple autocomplete select dropdown component for Vue apps for you!\n\n## Demo\n[Check it out on CodeSandbox](https://codesandbox.io/s/vue-template-sgjfj?fontsize=14)\n\n## What It Does\nvue-single-select provides a **simple** component for making long, unwieldy select boxes more friendly, like Chosen for jQuery.\n\n## How Simple?\n\nThis **simple**\n\n```html\n\u003cvue-single-select      \n    v-model=\"fruit\" \n    :options=\"['apple','cherry','banana','pear', 'tomato']\"\n\u003e\u003c/vue-single-select\u003e    \n```\n\n\u003cimg style=\"width: 500px\" src=\"https://raw.githubusercontent.com/robrogers3/vue-single-select/master/simple-single-select.png\"\u003e\n\n## What It Does Not Do\n\nNope no Multi Select. See vue-taggable-select for this.\n\n[Vue Taggable Select](https://www.npmjs.com/package/vue-taggable-select)\n\n### Install or Use Via CDN\n\n```html\n\u003cdiv id=\"app\"\u003e\n    \u003clabel\u003eChoose a fruit!\u003c/label\u003e\n    \u003cvue-single-select\n\t    v-model=\"fruit\"\n\t    :options=\"fruits\"\n    \u003e\u003c/vue-single-select\u003e\n\u003c/div\u003e\n```\n\n```html\n\u003cscript src=\"https://unpkg.com/vue@latest\"\u003e\u003c/script\u003e\n\u003cscript src=\"https://unpkg.com/vue-single-select@latest\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n new Vue({\n     el:\"#app\",\n     data: {\n         fruit: null,\n         fruits: ['peach','pear','apple','orange']\n     }\n });\n\u003c/script\u003e\n````\n\n### Install Via NPM\n\n```bash\n$ npm i vue-single-select\n```\n\n### Register it\n\nIn your component:\n\n```javascript\nimport VueSingleSelect from \"vue-single-select\";\nexport default {\ncomponents: {\n     VueSingleSelect\n  },\n  //...\n}\n```\n\nGlobally:\n\n```javascript\nimport VueSingleSelect from \"vue-single-select\";\nVue.component('vue-single-select', VueSingleSelect);\n```\n\n### Use It\n\n```html\n\u003cvue-single-select\n        v-model=\"fruit\"\n        :options=\"['apple','banana','cherry','tomato']\"\n        :required=\"true\"\n\u003e\u003c/vue-single-select\u003e\n```\n\n### Use It Again\n\n#### Specify a custom option label and option value\n\nHere each option refereneces a post title in the **posts** list in data.\nThe option value references a post id in the same list. Like:\n\n```\nposts: [{title: \"ok dude\", id: 1}, {title: \"awesome dude\", id: 2}, ...]\n```\n\n```\n\n```\n\n```html\n\u003cvue-single-select\n        name=\"maybe\"\n        placeholder=\"pick a post\"\n        you-want-to-select-a-post=\"ok\"\n        v-model=\"post\"\n        out-of-all-these-posts=\"makes sense\"\n        :options=\"posts\"\n        a-post-has-an-id=\"good for search and display\"\n        option-key=\"id\"\n        the-post-has-a-title=\"make sure to show these\"\n        option-label=\"title\"\n\u003e\u003c/vue-single-select\u003e\n```\n\n### Use It Again\n\n#### Specify a custom option label.\n\nHere the Option Label references a reply the **replies** list in data.\nWith a format like: \n```\nreplies: [{reply: \"ok dude\"}, {reply: \"awesome dude\"}, ...]\n```\n\n```html\n\u003cvue-single-select\n        you-want-to-select-a-reply=\"yes\"\n        v-model=\"reply\"\n        out-of-all-these-replies=\"yep\"\n        :options=\"replies\"\n        a-reply-only-has-a-reply=\"sounds about right\"\n        option-label=\"reply\"\n        seed-an-initial-value=\"what's seed mean?\"\n        initial=\"seed me\"\n        you-only-want-20-options-to-show=\"is 20 enough?\"\n        :max-results=\"20\"\n\u003e\u003c/vue-single-select\u003e\n```\n\n### Dont like the Styling?\n\nYou can override some of it. Like so:\n\n```html\n\u003cvue-single-select\n        id=\"selected-reply\"\n        name=\"a_reply\"\n        option-label=\"reply\"\n        v-model=\"reply\"\n        :options=\"replies\"\n        you-like-huge-dropdowns=\"1000px is long!\"\n        max-height=\"1000px\"\n        you-love-bootstrap=\"yes!!\"\n        :classes=\"{\n                    input: 'form-control',\n                    wrapper: 'form-group',\n                    icons: 'glyphicon',\n                    required: 'required'\n                    active: 'active',\n                    dropdown: 'dropdown'\n        }\"\n\u003e\u003c/vue-single-select\u003e\n```\n\nThen all you need to do is provide some class definitions like so:\n\n```css\n.form-control {\n    color: pink;\n    width: 10000px;\n    _go: nuts;\n}\n.glyphicon {\n    display:none;\n}\n.form-group {\n    background-color: pink;\n    font-size: 16px;\n}\n\n.required {\n    color: #721c24;\n    background-color: #f8d7da;\n    border-color: #f5c6cb;\n}\n.dropdown: {\n    color: violet;\n}\n.active {\n    background-color: lemonchiffon;\n}\n\n```\n\n**Note: Bootstrap 3 Users May want to increase the size of the icons.**\n\nIf so do this: \n```css\n.icons svg {\n    height: 1em;\n    width: 1em;\n}\n```\n\n#### See defaults below.\n\n### Dont like the styling at all?\n\nUse the slots option to really mix it up.\n\nThis is a little advanced, but it's not too hard. Take a look:\n\n```html\n\u003csingle-select\n    option-label=\"title\"\n    v-model=\"thread\" \n    :options=\"threads\" \n    max-height=\"300px\"\n    \u003e\n        \u003ctemplate slot=\"option\" slot-scope=\"{option, idx}\"\u003e\n            \u003cdiv style=\"display:flex;padding: 2px;font-size: 2rem;\"\n                :class=\"idx % 2 ? 'emoji-happy' : 'emoji-sad'\"\n                :style=\"idx % 2 ? 'color:red' : 'color:blue'\"\u003e\n                \u003cspan style=\"margin-left: 1rem;\"\u003e\n                    {{idx}}\u003c/span\u003e\n                \u003cspan style=\"margin-left: 1rem;\"\u003e\n                    {{option.title}}\u003c/span\u003e\n            \u003c/div\u003e\n        \u003c/template\u003e\n    \u003c/single-select\u003e\n```\n\n```css\n.emoji-happy::before {\n    content:\"\\1F600\"\n}\n.emoji-sad::before {\n    content:\"\\1F622\"\n}\n```\nThe key is the **template** element.\n\nHere I give you the option and the current index. From there you can add html, add exta info, or a smiley face.\n\nAnd here you go:\n\n![Image of Smiley](https://raw.githubusercontent.com/robrogers3/vue-single-select/master/single-select-happy.png)\n### Kitchen Sink\n\nMeh, see props below.\n\n## Why vue-single-select is better\n\n1.  It handles custom label/value props for displaying options.\n\n    Other select components require you to conform to their format. Which often means data wrangling.\n\n2.  It's easier on the DOM.\n\n    Other components will load up all the options available in the select element. This can be heavy. vue-single-select makes an executive decision that you probably will not want to scroll more than N options before you want to narrow things down a bit. You can change this, but the default is 30.\n\n3.  Snappy Event Handling\n\n    - up and down arrows for selecting options\n    - enter to select first match\n    - remembers selection on change\n    - hit the escape key to, well, escape\n\n4.  Lightweight\n\n    - Why are the other packages so big and actually have dependencies?\n\n5. It works for regular 'POST backs' to the server.\n\n    If you are doing a regular post or just gathering the form data you don't need to do anything extra to provide a name and value for the selected option.\n\n6. Mine just looks nicer\n\n7. It's simple!!\n\n## Available Props:\n\nThere are more props than I'd like. But I needed them so you might too.\n\n```javascript\n    props: {\n    value: {\n      required: true\n    },\n    // Give your element a name.\n    // Good for doing a POST\n    name: {\n      type: String,\n      required: false,\n      default: () =\u003e \"\"\n    },\n    // Your list of things for the select\n    options: {\n      type: Array,\n      required: false,\n      default: () =\u003e []\n    },\n    // Tells vue-single-select what key to use\n    // for generating option labels\n    optionLabel: {\n      type: String,\n      required: false,\n      default: () =\u003e null\n    },\n    // Tells vue-single-select the value\n    // you want populated in the select for the \n    // input\n    optionKey: {\n      type: String,\n      required: false,\n      default: () =\u003e null\n    },\n    placeholder: {\n      type: String,\n      required: false,\n      default: () =\u003e \"Search Here\"\n    },\n    maxHeight: {\n      type: String,\n      default: () =\u003e \"220px\",\n      required: false\n    },\n    // Give your input an html element id\n    inputId: {\n      type: String,\n      default: () =\u003e \"single-select\",\n      required: false\n    },\n    //Customize the styling by providing \n    //these FIVE custom style definitions.\n    classes: {\n      type: Object,\n      required: false,\n      default: () =\u003e {\n        return {\n          wrapper: \"single-select-wrapper\",\n          input: \"search-input\",\n          icons: \"icons\",\n          required: \"required\",\n          activeClass: 'active',\n          dropdown: 'dropdown'\n        };\n      }\n    },\n    // Seed search text with initial value\n    initial: {\n      type: String,\n      required: false,\n      default: () =\u003e null\n    },\n    // Disable it!\n    disabled: {\n      type: Boolean,\n      required: false,\n      default: () =\u003e false\n    },\n    // Make it required\n    required: {\n      type: Boolean,\n      required: false,\n      default: () =\u003e false\n    },\n    // Number of results to show at a time\n    maxResults: {\n      type: Number,\n      required: false,\n      default: () =\u003e 30\n    },\n    // meh...\n    tabindex: {\n      type: String,\n      required: false,\n      default: () =\u003e {\n        return \"\";\n      }\n    },\n    // Tell vue-single-select what to display\n    // as the selected option\n    getOptionDescription: {\n      type: Function,\n      default: function (option) {\n        if (this.optionKey \u0026\u0026 this.optionLabel) {\n          return option[this.optionKey] + \" \" + option[this.optionLabel];\n        }\n        if (this.optionLabel) {\n          return option[this.optionLabel];\n        }\n        if (this.optionKey) {\n          return option[this.optionKey];\n        }\n            return option;\n      }\n    },\n    // Use this to actually give vue-single-select\n    // a value for doing a POST\n    getOptionValue: {\n      type: Function,\n      default: function (option) {\n        if (this.optionKey) {\n          return option[this.optionKey];\n        }\n        \n        if (this.optionLabel) {\n          return option[this.optionLabel];\n        }\n\n        return option;\n      }\n    },\n    //Default filtering, provide your own for fun\n    //Like startsWith instead of includes\n    filterBy: {\n      type: Function,\n      default: function (option) {\n        if (this.optionLabel \u0026\u0026 this.optionKey) {\n          return (\n            option[this.optionLabel]\n              .toString()\n              .toLowerCase()\n              .includes(this.searchText.toString().toLowerCase()) ||\n              option[this.optionKey]\n              .toString()\n              .toLowerCase()\n              .includes(this.searchText.toString().toLowerCase())\n          )\n        }\n        \n        if (this.optionLabel) {\n          return option[this.optionLabel]\n            .toString()\n            .toLowerCase()\n            .includes(this.searchText.toString().toLowerCase())\n        }\n        \n        if (this.optionKey) {\n          option[this.optionKey]\n            .toString()\n            .toLowerCase()\n            .includes(this.searchText.toString().toLowerCase())\n        }\n        \n        return option\n          .toString()\n          .toLowerCase()\n          .includes(this.searchText.toString().toLowerCase())\n      }\n    }\n  }\n  ```\n\n## Q\u0026A\n\nQ. _What about Ajax?_\n\nA. Good question. Why aren't you passing data in as a prop?\nSeriously, this is just a widget why does it need knowledge of it's data source?\n\nQ. _How do I change how items are filtered?_\n\nA. Easy. See prop above, `matchingOptions`. Just override it with your own method as a prop.\n\nQ. _What about Templating?_\n\nA. What about it? Just use the new scoped slots!\n\nQ. _What about Multiple Selects?_\n\nA. Nope not found here. See vue-taggable-select\n\nQ. _Can I trust this?_\n\nA. Yep. It's backed by tests using jest and vue test utils.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrogers3%2Fvue-single-select","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobrogers3%2Fvue-single-select","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobrogers3%2Fvue-single-select/lists"}