Skip to content

Commit

Permalink
Merge pull request #256 from bjester/textbox-autofocus-delay-invalid
Browse files Browse the repository at this point in the history
Fix textbox autofocus triggering invalid message
  • Loading branch information
indirectlylit authored Sep 2, 2021
2 parents cb6e4df + d502f7a commit 5e008df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ docs/jsdocs.js

# IDE
.idea
kolibri-design-system.iml
8 changes: 7 additions & 1 deletion lib/KTextbox/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
return {
currentText: this.value,
changedOrFocused: false,
hasBeenFocused: false,
};
},
computed: {
Expand Down Expand Up @@ -203,7 +204,11 @@
/**
* Emitted with `focus` events
*/
this.changedOrFocused = true;
// Skip first focus event if autofocus is enabled
if (!this.autofocus || this.hasBeenFocused) {
this.changedOrFocused = true;
}
this.hasBeenFocused = true;
this.$emit('focus', e);
},
/**
Expand All @@ -212,6 +217,7 @@
*/
focus() {
this.changedOrFocused = true;
this.hasBeenFocused = true;
this.$refs.textbox.$el.querySelector('input').focus();
},
},
Expand Down
10 changes: 5 additions & 5 deletions lib/keen/UiTextbox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
</div>
</label>

<div v-if="hasFeedback || maxlength" class="ui-textbox-feedback">
<div v-if="showHelp || hasErrorFeedback || maxlength" class="ui-textbox-feedback">
<div v-if="showError" class="ui-textbox-feedback-text" style="{ color: $themeTokens.error }">
<slot name="error">
{{ error }}
Expand All @@ -104,7 +104,7 @@
</div>

<!-- Placeholder to keep the text height spacing in place even when
not showing any errors -->
not showing any errors -->
<div v-else class="ui-textbox-feedback-text">
&nbsp;
</div>
Expand Down Expand Up @@ -282,12 +282,12 @@
return this.value ? this.value.length : 0;
},
hasFeedback() {
return this.showError || this.showHelp;
hasErrorFeedback() {
return Boolean(this.error) || Boolean(this.$slots.error);
},
showError() {
return this.invalid && (Boolean(this.error) || Boolean(this.$slots.error));
return this.invalid && this.hasErrorFeedback;
},
showHelp() {
Expand Down

0 comments on commit 5e008df

Please sign in to comment.