Focus in input after text clear (#1669)

* * Focus in input after text clear

* "makes the button disappear after clicking"

* animation

* Fix button title text

* Really remove/hide the button after CSS animation

* Fix hovered button overlapping text input box

* Fix incorrect initial value
This commit is contained in:
PikachuEXE 2021-09-23 14:45:14 +08:00 committed by GitHub
parent 5c83dd8790
commit 56b562966f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 7 deletions

View File

@ -11,13 +11,19 @@
cursor: pointer; cursor: pointer;
border-radius: 200px 200px 200px 200px; border-radius: 200px 200px 200px 200px;
color: var(--primary-text-color); color: var(--primary-text-color);
opacity: 0;
-moz-transition: background 0.2s ease-in, opacity 0.2s ease-in;
-o-transition: background 0.2s ease-in, opacity 0.2s ease-in;
transition: background 0.2s ease-in, opacity 0.2s ease-in;
} }
.clearInputTextButton:hover { .clearInputTextButton:hover {
background-color: var(--side-nav-hover-color); background-color: var(--side-nav-hover-color);
-moz-transition: background 0.2s ease-in; }
-o-transition: background 0.2s ease-in; .clearInputTextButton.visible {
transition: background 0.2s ease-in; opacity: 1;
} }
.forceTextColor .clearInputTextButton:hover { .forceTextColor .clearInputTextButton:hover {
@ -82,7 +88,7 @@
.inputAction { .inputAction {
position: absolute; position: absolute;
padding: 10px; padding: 10px 8px;
top: 5px; top: 5px;
right: 0px; right: 0px;
cursor: pointer; cursor: pointer;

View File

@ -60,7 +60,10 @@ export default Vue.extend({
showOptions: false, showOptions: false,
selectedOption: -1, selectedOption: -1,
isPointerInList: false isPointerInList: false
} },
// This button should be invisible on app start
// As the text input box should be empty
clearTextButtonVisible: false
} }
}, },
computed: { computed: {
@ -74,11 +77,28 @@ export default Vue.extend({
idDataList: function () { idDataList: function () {
return `${this.id}_datalist` return `${this.id}_datalist`
},
inputDataPresent: function () {
return this.inputData.length > 0
} }
}, },
watch: { watch: {
value: function (val) { value: function (val) {
this.inputData = val this.inputData = val
},
inputDataPresent: function (newVal, oldVal) {
if (newVal) {
// The button needs to be visible **immediately**
// To allow user to see the transition
this.clearTextButtonVisible = true
} else {
// Hide the button after the transition
// 0.2s in CSS = 200ms in JS
setTimeout(() => {
this.clearTextButtonVisible = false
}, 200)
}
} }
}, },
mounted: function () { mounted: function () {
@ -104,6 +124,10 @@ export default Vue.extend({
handleClearTextClick: function () { handleClearTextClick: function () {
this.inputData = '' this.inputData = ''
this.$emit('input', this.inputData) this.$emit('input', this.inputData)
// Focus on input element after text is clear for better UX
const inputElement = document.getElementById(this.id)
inputElement.focus()
}, },
addListener: function () { addListener: function () {

View File

@ -21,12 +21,15 @@
/> />
</label> </label>
<font-awesome-icon <font-awesome-icon
v-if="showClearTextButton" v-if="showClearTextButton && clearTextButtonVisible"
icon="times-circle" icon="times-circle"
class="clearInputTextButton" class="clearInputTextButton"
:class="{
visible: inputDataPresent
}"
tabindex="0" tabindex="0"
role="button" role="button"
title="$t('Search Bar.Clear Input')" :title="$t('Search Bar.Clear Input')"
@click="handleClearTextClick" @click="handleClearTextClick"
@keydown.space.prevent="handleClearTextClick" @keydown.space.prevent="handleClearTextClick"
@keydown.enter.prevent="handleClearTextClick" @keydown.enter.prevent="handleClearTextClick"