Skip to content

Commit

Permalink
[qa] refactor SearchField widget with v-model
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoPennec committed Oct 6, 2023
1 parent 59202e8 commit b546e33
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions src/components/widgets/SearchField.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div class="flexrow search-field-wrapper" ref="wrapper" @click="focus">
<div class="flexrow search-field-wrapper" :class="{ focused }" @click="focus">
<div class="flexrow-item">
<search-icon class="search-icon" />
</div>
Expand All @@ -12,8 +12,9 @@
:placeholder="placeholder"
@input="onSearchChange"
@keyup.enter="onEnterPressed"
@focus="setFocusedStyle"
@blur="unsetFocusedStyle"
@focus="focused = true"
@blur="focused = false"
v-model.trim="search"
v-focus="focusOptions"
/>
</div>
Expand All @@ -37,7 +38,10 @@ export default {
name: 'search-field',
data() {
return {}
return {
search: '',
focused: false
}
},
props: {
Expand All @@ -49,6 +53,7 @@ export default {
type: Boolean,
default: false
},
// FIXME:property no longer used in component
active: {
type: Boolean,
default: true
Expand All @@ -63,53 +68,36 @@ export default {
SearchIcon
},
computed: {},
methods: {
onSearchChange() {
this.$emit('change', this.$refs.input.value)
this.$emit('change', this.search)
},
onEnterPressed() {
this.$emit('enter', this.$refs.input.value)
this.$emit('enter', this.search)
},
onSaveClicked() {
const value = this.$refs.input.value.trim()
if (value.length > 0) {
if (this.canSave) this.$emit('save', value)
if (this.search && this.canSave) {
this.$emit('save', this.search)
}
},
getValue() {
if (this.$refs.input) {
return this.$refs.input.value
} else {
return ''
}
return this.search
},
setValue(value) {
this.$refs.input.value = value
this.search = value
},
focus(options) {
if (this.$refs.input) {
this.$refs.input.focus(options)
}
this.$refs.input?.focus(options)
},
clearSearch() {
this.setValue('')
this.search = ''
this.onSearchChange()
},
setFocusedStyle() {
this.$refs.wrapper.className = 'flexrow search-field-wrapper focused'
},
unsetFocusedStyle() {
this.$refs.wrapper.className = 'flexrow search-field-wrapper'
}
}
}
Expand Down Expand Up @@ -151,6 +139,8 @@ export default {
}
.search-icon {
width: 20px;
margin-top: 5px;
color: var(--text);
}
Expand Down Expand Up @@ -197,11 +187,6 @@ export default {
border-color: $green;
}
.search-icon {
width: 20px;
margin-top: 5px;
}
@media screen and (max-width: 768px) {
.search-input {
width: 200px;
Expand Down

0 comments on commit b546e33

Please sign in to comment.