From f2db2fb00ef7a89e80baccb5227865bfb30faff4 Mon Sep 17 00:00:00 2001 From: Julien Croain Date: Mon, 12 Feb 2018 16:28:16 +0100 Subject: [PATCH 1/2] Add prop on component to manage the behaviour preventDefaultOnEnter --- App.vue | 15 +++++++++++++++ README.md | 14 +++++++++----- src/VueTagInput.vue | 10 ++++++++++ 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/App.vue b/App.vue index 186d0e3..d91e4b3 100644 --- a/App.vue +++ b/App.vue @@ -1,5 +1,6 @@ @@ -22,6 +36,7 @@ export default { tags: [], // suggestions: ['Japan', 'Taiwan', 'Africa', 'America', 'Canada', 'Finland', 'China'], suggestions: ['中國', '中文', '中午', '中飯'], + preventDefaultOnEnter: true }; }, }; diff --git a/README.md b/README.md index 99fb173..ba8480e 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,8 @@ An array of tag objects. Each tag need an `id` and a `text` property which is us ```js // Recommended: Pass Object [ - {id: 1, name: 'Apple'}, - {id: 2, name: 'Banana'}, + {id: 1, text: 'Apple'}, + {id: 2, text: 'Banana'}, ... ] // Quick: Pass String @@ -85,8 +85,8 @@ An array of suggestions that are used as basis for showing autocomplete. Each ta ```js // Recommended: Pass Object [ - {id: 1, name: 'Apple'}, - {id: 2, name: 'Banana'}, + {id: 1, text: 'Apple'}, + {id: 2, text: 'Banana'}, ... ] // Quick: Pass String @@ -138,7 +138,7 @@ Array of characters matching keyboard event key values. This is useful when need Default: `false` If set to `true`, it will be possible to add new items only from the autocomplete dropdown. -#### allowDuplicates - {Boolean} +#### allowDuplicated - {Boolean} Default: `false` Allows users to add duplicated tags. If it's `false`, the duplicated tag would play animation with [`errorAninmatedClass`](#errorAninmatedClass---String) to hint the user. @@ -197,6 +197,10 @@ export default { ``` +#### preventDefaultOnEnter - {Boolean} +Default: `false` +Prevent default when user tap ENTER to avoid the form submission. + ## Events #### add diff --git a/src/VueTagInput.vue b/src/VueTagInput.vue index 344d506..5a9173c 100644 --- a/src/VueTagInput.vue +++ b/src/VueTagInput.vue @@ -110,6 +110,11 @@ export default { required: false, default: () => ({}), }, + preventDefaultOnEnter: { + type: Boolean, + required: false, + default: false, + }, }, data() { return { @@ -197,6 +202,11 @@ export default { if (e.keyCode === KEYS.TAB || e.keyCode === KEYS.UP || e.keyCode === KEYS.DOWN) { e.preventDefault(); } + + // prevent ENTER key to keep cursor position in input + if (e.keyCode === KEYS.ENTER && this.preventDefaultOnEnter) { + e.preventDefault(); + } }, handleComposition(e) { if (e.type === 'compositionend') { From 87e4a7856d14dd0575ce0b5f06e4c668f87e8eef Mon Sep 17 00:00:00 2001 From: Julien Croain Date: Mon, 12 Feb 2018 16:37:57 +0100 Subject: [PATCH 2/2] Fix CI error --- App.vue | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/App.vue b/App.vue index d91e4b3..b8ec07d 100644 --- a/App.vue +++ b/App.vue @@ -8,10 +8,12 @@ :only-from-suggestions="false" :quick-mode="true" /> -
+
Inside a Form
- Prevent default on enter + Prevent default on enter