Skip to content

Commit

Permalink
feat(props): added new prop disableFirstItemSelectOnEnter
Browse files Browse the repository at this point in the history
disable the selection of the first item from the list of items in menu when to press enter (when no
item is selected)

re #53
  • Loading branch information
iliyaZelenko committed Mar 8, 2019
1 parent 32a9635 commit 1483b9e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
3 changes: 2 additions & 1 deletion gh-pages-src/pages/dev/Example4.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@

Search: "{{ search }}"

<!--arrows-disable-instant-selection :search.sync="search"-->
<!--disable-first-item-select-on-enter :search.sync="search"-->
<cool-select
ref="select"
v-model="selected"
:items="items"
:search-text.sync="search"
arrows-disable-instant-selection
placeholder="Select name"
@select="onSelect"
@focus="onFocus"
Expand Down
42 changes: 22 additions & 20 deletions src/eventsListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,30 @@ export default {
e.preventDefault()
},
onEnter () {
// if (this.arrowsIndex === null) {
// this.selectedItem = this.itemsComputed[0]
// }
//
// this.fireSelectEvent(this.selectedItem)

if (!this.arrowsIndex && this.hasMenu) {
const firstItem = this.itemsComputed[0]

if (!firstItem) return

this.fireSelectEvent(
this.selectedItem = firstItem
)
}
if (this.arrowsDisableInstantSelection && this.selectedItemByArrows) {
this.fireSelectEvent(
this.selectedItem = this.selectedItemByArrows
)
if (this.hasMenu) {
let needToResetSearch = false
// если не выбрано через стрелки, то выбирать первый элемент
if (!this.arrowsIndex && !this.disableFirstItemSelectOnEnter) {
const firstItem = this.itemsComputed[0]

if (!firstItem) return

this.fireSelectEvent(
this.selectedItem = firstItem
)
needToResetSearch = true
}
// если arrowsDisableInstantSelection и выбран элемент через стрелки (подсвечен), то сделать его выбранным
if (this.arrowsDisableInstantSelection && this.selectedItemByArrows) {
this.fireSelectEvent(
this.selectedItem = this.selectedItemByArrows
)
needToResetSearch = true
}

if (needToResetSearch) this.setSearchData('')
}

this.setSearchData('')
// show / hide menu
this.hasMenu ? this.hideMenu() : this.showMenu()
},
Expand Down
5 changes: 5 additions & 0 deletions src/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,10 @@ export default {
type: Number,
default: 10,
note: 'the number of items added to the scrollItemsLimit prop after scrolling to the end of the scroll. Also see scrollItemsLimitAddAfterScroll prop.'
},
disableFirstItemSelectOnEnter: {
type: Boolean,
default: false,
note: 'disable the selection of the first item from the list of items in menu when to press enter (when no item is selected)'
}
}

0 comments on commit 1483b9e

Please sign in to comment.