Skip to content

Commit

Permalink
[Vue 3] Added new option to prevent autofocus on input search (#1544)
Browse files Browse the repository at this point in the history
* Added new option to prevent autofocus on input search

* Refactor condition to prevent run extra code

Co-authored-by: Akshay Jat <[email protected]>
  • Loading branch information
JoseVte and akki-jat authored Oct 21, 2022
1 parent 84ad5a8 commit 218045f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default [
file: 'dist/vue-multiselect.esm.js'
},
plugins: [
css({output:'vue-multiselect.esm.css'}),
css({output: 'vue-multiselect.esm.css'}),
vue()
]
},
Expand All @@ -22,7 +22,7 @@ export default [
file: 'dist/vue-multiselect.ssr.js'
},
plugins: [
css({output:'vue-multiselect.ssr.css'}),
css({output: 'vue-multiselect.ssr.css'}),
vue({ template: { optimizeSSR: true } })
]
},
Expand All @@ -39,7 +39,7 @@ export default [
}
},
plugins: [
css({output:'vue-multiselect.css'}),
css({output: 'vue-multiselect.css'}),
vue()
]
}
Expand Down
13 changes: 11 additions & 2 deletions src/multiselectMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ export default {
preselectFirst: {
type: Boolean,
default: false
},
/**
* Prevent autofocus
* @default false
* @type {Boolean}
*/
preventAutofocus: {
type: Boolean,
default: false
}
},
mounted () {
Expand Down Expand Up @@ -649,8 +658,8 @@ export default {
/* istanbul ignore else */
if (this.searchable) {
if (!this.preserveSearch) this.search = ''
this.$nextTick(() => this.$refs.search && this.$refs.search.focus())
} else {
if (!this.preventAutofocus) this.$nextTick(() => this.$refs.search && this.$refs.search.focus())
} else if (!this.preventAutofocus) {
this.$el.focus()
}
this.$emit('open', this.id)
Expand Down

0 comments on commit 218045f

Please sign in to comment.