Skip to content

Commit

Permalink
improvement(selecttextonfocus prop): fix setTimeout delay for Chrome …
Browse files Browse the repository at this point in the history
…and other small changes

re #235
  • Loading branch information
iliyaZelenko committed Oct 24, 2019
1 parent a003167 commit 9f0e223
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
18 changes: 1 addition & 17 deletions gh-pages-src/pages/dev/Example5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,7 @@
<b>Selected:</b> {{ selected || 'not chosen' }}.
<br><br>

<form @submit="onSubmit">
<cool-select
ref="select"
v-model="selected"
:items="items"
placeholder="Select name"
@keydown.enter.native="onEnter"
/>
</form>

<br>
{{ selectTextOnFocus }}

<cool-select
ref="select"
Expand Down Expand Up @@ -148,12 +138,6 @@ export default {
}
},
methods: {
onSubmit () {
alert('Submit!')
},
onEnter () {
alert('onEnter!')
},
validate () {
this.errorMessage = this.selected ? null : 'This is required field!'
}
Expand Down
10 changes: 9 additions & 1 deletion src/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,12 @@ export default {
this.$refs['IZ-select__input-for-text'].focus()
},
setInputSelected () {
this.$refs['IZ-select__input-for-text'].select()
setTimeout(() => {
// Вроде не нужно https://stackoverflow.com/a/5001669/5286034
// if (isTextSelected(this.$refs['IZ-select__input-for-text'])) return
this.$refs['IZ-select__input-for-text'].select()
}, 100)
},
setFocused (byInput = false) {
if (this.focused || this.disabled || this.readonly) return
Expand All @@ -342,11 +347,14 @@ export default {
})
}
if (this.selectTextOnFocus) this.setInputSelected()
this.focused = true
this.showMenu()
this.$emit('focus')
},
// TODO правильнее blurred!
setBlured () {
if (this.resetSearchOnBlur) {
this.setSearchData('')
Expand Down
4 changes: 0 additions & 4 deletions src/eventsListeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ export default {

this.setFocused()
this.showMenu()

// select text input if enabled
if (!this.selectTextOnFocus) return
setTimeout(this.setInputSelected, 0)
},
// on click on item
onClickSelectItem (item) {
Expand Down

0 comments on commit 9f0e223

Please sign in to comment.