Skip to content

Commit

Permalink
fix(component): fix tab navigation
Browse files Browse the repository at this point in the history
fix #98
  • Loading branch information
Ilya authored and Ilya committed Mar 29, 2019
1 parent 72eab24 commit a03694b
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion gh-pages-src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@
href="https://github.com/iliyaZelenko/vue-cool-select"
target="_blank"
class="ml-2"
round
rounded
>
Visit github
</v-btn>
Expand Down
8 changes: 6 additions & 2 deletions gh-pages-src/pages/dev/Example5.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
:readonly="readonly"
:disable-search="disableSearch"
placeholder="Select name"
@blur="validate"
/>

<br>
Expand Down Expand Up @@ -72,9 +71,14 @@ export default {
items: '[{"first_name":"one"}, {"first_name":"two"}, {"first_name":"three"}, {"first_name":"four"}, {"first_name":"five"}]',
errorMessage: null
}),
watch: {
selected () {
this.validate()
}
},
methods: {
validate () {
this.errorMessage = !this.selected ? 'This is required field!' : null
this.errorMessage = this.selected ? null : 'This is required field!'
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/component.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<template>
<!---->
<div
ref="IZ-select"
:tabindex="disableSearch ? 1 : -1"
class="IZ-select"
tabindex="0"
@keydown.up="onSelectByArrow"
@keydown.down="onSelectByArrow"
@keydown.enter="onEnter"
@keydown.tab.esc="setBlured"
@mousedown="onClick"
@focus="onFocus"
>
<div
ref="IZ-select__input"
Expand Down Expand Up @@ -37,12 +39,14 @@
:class="inputForTextClass"
:disabled="disableSearch || disabled"
:readonly="readonly"
:tabindex="disableSearch ? -1 : 1"
type="text"
role="combobox"
autocomplete="off"
@keyup="onSearchKeyUp"
@keydown="onSearchKeyDown"
@input="onSearch"
@focus="onFocus"
>
</div>

Expand Down
10 changes: 6 additions & 4 deletions src/computed.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ export default {
return window.innerWidth <= 900 && window.innerHeight <= 900
},
menuDynamicStyles () {
let obj = {
// ширина такая же как и у поля ввода
'width': this.$refs['IZ-select__input'].offsetWidth + 'px',
const input = this.$refs['IZ-select__input']
const obj = {
// ширина и смещение слева такие же как и у поля ввода
width: input.offsetWidth + 'px',
left: input.offsetLeft + 'px',
'pointer-events': this.hasMenu ? 'auto' : 'none'
}

if (this.disableSearch) {
obj.top = this.$refs['IZ-select__input'].offsetTop + 'px'
obj.top = input.offsetTop + 'px'
}

return obj
Expand Down
3 changes: 3 additions & 0 deletions src/eventsListeners.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { scrollIfNeeded } from '~/helpers'

export default {
onFocus () {
this.setFocused()
},
onSelectByArrow (e) {
e.preventDefault()

Expand Down
9 changes: 5 additions & 4 deletions src/styles/main.styl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
.IZ-select *
box-sizing: border-box;
.IZ-select
*
box-sizing: border-box;

.fade
&-leave-active
position: absolute
position: absolute;

&-enter-active, &-leave, &-leave-to
transition: opacity .2s;

&-enter, &-leave-to
opacity: 0
opacity: 0;

4 changes: 2 additions & 2 deletions tests/unit/component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ describe('MainComponent.vue', () => {
let styles = wrapper.vm.menuDynamicStyles

expect(
!!(styles.width && styles['pointer-events'] && !styles.top)
!!(styles.width && styles.left && styles['pointer-events'] && !styles.top)
).toBe(true)

wrapper.setProps({
Expand All @@ -393,7 +393,7 @@ describe('MainComponent.vue', () => {
styles = wrapper.vm.menuDynamicStyles

expect(
!!(styles.width && styles['pointer-events'] && styles.top)
!!(styles.width && styles.left && styles['pointer-events'] && styles.top)
).toBe(true)
})
})

0 comments on commit a03694b

Please sign in to comment.