diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..999ac4a --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,2 @@ +github: [sagalbot] + diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..665a970 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +* +!src/**/* +!dist/**/* +.DS_Store diff --git a/dev/Dev.vue b/dev/Dev.vue index 6631345..4002212 100644 --- a/dev/Dev.vue +++ b/dev/Dev.vue @@ -1,8 +1,28 @@ @@ -15,11 +35,17 @@ import Sandbox from '../docs/.vuepress/components/Sandbox'; import countries from '../docs/.vuepress/data/countryCodes'; import books from '../docs/.vuepress/data/books'; +const randomBook = (id) => { + const rand = Math.floor(Math.random() * Math.floor(books.length - 1)); + return {...books[rand], id}; +} + export default { components: {vSelect, Sandbox, ListSelect, Paginated}, computed: { countries: () => countries, - books: () => books, + books: () => Array(100).fill(0).map((num, index) => randomBook(index)), + jest: () => ({value: [{label: "one"}], options: [{label: "one"}]}), }, }; diff --git a/docs/.vuepress/components/LimitSelectionQuantity.vue b/docs/.vuepress/components/LimitSelectionQuantity.vue new file mode 100644 index 0000000..f6890b7 --- /dev/null +++ b/docs/.vuepress/components/LimitSelectionQuantity.vue @@ -0,0 +1,21 @@ + + diff --git a/docs/.vuepress/components/UnselectableExample.vue b/docs/.vuepress/components/UnselectableExample.vue new file mode 100644 index 0000000..ee7d935 --- /dev/null +++ b/docs/.vuepress/components/UnselectableExample.vue @@ -0,0 +1,16 @@ + + diff --git a/docs/.vuepress/config.js b/docs/.vuepress/config.js index 1f2e6a0..2bed2c8 100644 --- a/docs/.vuepress/config.js +++ b/docs/.vuepress/config.js @@ -118,6 +118,7 @@ module.exports = { collapsable: false, children: [ ['guide/validation', 'Validation'], + ['guide/selectable', 'Limiting Selections'], ['guide/vuex', 'Vuex'], ['guide/ajax', 'AJAX'], ['guide/loops', 'Using in Loops'], diff --git a/docs/api/props.md b/docs/api/props.md index 80fefce..2ae8284 100644 --- a/docs/api/props.md +++ b/docs/api/props.md @@ -339,12 +339,22 @@ createOption: { ## resetOnOptionsChange -When false, updating the options will not reset the select value +When false, updating the options will not reset the selected value. + +Since `v3.4+` the prop accepts either a `boolean` or `function` that returns a `boolean`. + +If defined as a function, it will receive the params listed below. ```js +/** +* @type {Boolean|Function} +* @param {Array} newOptions +* @param {Array} oldOptions +* @param {Array} selectedValue +*/ resetOnOptionsChange: { - type: Boolean, - default: false + default: false, + validator: (value) => ['function', 'boolean'].includes(typeof value) }, ``` diff --git a/docs/guide/selectable.md b/docs/guide/selectable.md new file mode 100644 index 0000000..954fc73 --- /dev/null +++ b/docs/guide/selectable.md @@ -0,0 +1,44 @@ +## Selectable Prop + +The `selectable` prop determines if an option is selectable or not. If `selectable` returns false +for a given option, it will be displayed with a `vs__dropdown-option--disabled` class. The option +will be disabled and unable to be selected. + +```js +selectable: { + type: Function, + /** + * @param {Object|String} option + * @return {boolean} + */ + default: option => true, +}, +``` + +### Example + +Here `selectable` is used to prevent books by a certain author from being chosen. In this case, +the options passed to the component are objects: + +```json +{ + title: "Right Ho Jeeves", + author: { firstName: "P.D", lastName: "Woodhouse" }, +} +``` + +This object will be passed to `selectable`, so we can check if the author should be selectable or not. + + + +<<< @/.vuepress/components/UnselectableExample.vue{6} + +## Limiting the Number of Selections + +`selectable` can also be used a bit more creatively to limit the number selections that can be made +within the component. In this case, the user can select any author, but may only select a maximum +of three books. + + + +<<< @/.vuepress/components/LimitSelectionQuantity.vue{8} diff --git a/package.json b/package.json index beb7fd1..3ee8cfb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-select", - "version": "3.2.0", + "version": "3.4.0", "description": "Everything you wish the HTML