Skip to content

Commit e0dede2

Browse files
iamzjohnisneezy
authored andcommitted
add ability to set limit to dropdown visible options (#18)
* adds limit prop and control in Vselectize * adds documentation * updates change.log * Update CHANGELOG.md
1 parent 49720fe commit e0dede2

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
## [unreleased]
8+
### Added
9+
- add ability to limit dropdown options using `limit` property [#14](https://github.com/isneezy/vue-selectize/issues/9)
10+
### Fixed
11+
- long phrases were get truncated or hidden behind
812

913
## [0.3.0] - 2018-07-26
1014
### Added
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<div>10 Countries:</div>
4+
<v-selectize :options="options" v-model="selected" :limit="limit" key-by="id" label="name" :keys="['name', 'id']"/>
5+
<div>Current Value: {{ selected }}</div>
6+
</div>
7+
</template>
8+
9+
<script>
10+
import VSelectize from '@isneezy/vue-selectize'
11+
import countries from './countries'
12+
export default {
13+
name: 'limit-dropdown-options',
14+
data: () => ({
15+
options: countries,
16+
selected: null,
17+
limit: 10
18+
}),
19+
components: {VSelectize}
20+
}
21+
</script>

docs/guide/examples/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ A good example of:
3333

3434
<<< @/docs/.vuepress/components/CountrySelector.vue
3535

36+
## Limit Dropdown option
37+
<limit-dropdown-options/>
38+
This demo limits the dropdown to have only 10 contries listed.
39+
40+
<<< @/docs/.vuepress/components/LimitDropdownOptions.vue
41+
3642
## Remote Source — Github
3743
<remote-git-hub/>
3844
This example shows how to integrate third-party data from the GitHub API.

src/components/VSelectize.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ export default {
8181
*/
8282
value: {default: null, type: [Array, Object, String, Number]},
8383
84+
/**
85+
* The limit/max of options to show in dropdown
86+
*/
87+
limit: {default: 0, type: [Number]},
88+
8489
/**
8590
* Allows input to be disabled and hides dropdown options
8691
*/
@@ -163,7 +168,8 @@ export default {
163168
minMatchCharLength: 1,
164169
keys: this.keys
165170
})
166-
return this.searchText.length && !this.disableSearch ? fuse.search(this.searchText) : this.formattedOptions
171+
const options = this.searchText.length && !this.disableSearch ? fuse.search(this.searchText) : this.formattedOptions
172+
return this.limit > 0 ? options.slice(0, this.limit) : options
167173
},
168174
169175
/**

0 commit comments

Comments
 (0)