Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: button Add instead of input when nothing is added #173

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .directory
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[Dolphin]
Timestamp=2022,5,3,13,27,8
Version=4
ViewMode=2
2 changes: 1 addition & 1 deletion package.json → package.bak.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"type": "git",
"url": "https://github.com/JohMun/vue-tags-input.git"
},
"main": "dist/vue-tags-input.js",
"main": "vue-tags-input/vue-tags-input.vue",
"scripts": {
"dev": "npm run docs",
"docs": "cross-env NODE_ENV=development webpack-dev-server --hot --config ./build/docs.config.js",
Expand Down
40 changes: 38 additions & 2 deletions vue-tags-input/vue-tags-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
deletionMarkTime: null,
selectedItem: null,
focused: null,
mouseOverWorkingPlace: false,
};
},
computed: {
Expand Down Expand Up @@ -128,8 +129,9 @@ export default {
// Focuses the input of a tag
focus(index) {
this.$nextTick(() => {
const el = this.$refs.tagCenter[index].querySelector('input.ti-tag-input');
if (el) el.focus();
// const el = this.$refs.tagCenter[index].querySelector('input.ti-tag-input');
// if (el) el.focus();
this.$refs.newTagInput.focus();
});
},
quote(regex) {
Expand Down Expand Up @@ -366,8 +368,42 @@ export default {
if (this.addOnBlur && this.focused) this.performAddTags(this.newTag);

// Hide autocomplete layer
this.close();
},


open(focus=true) {
if (this.preventAdd) {
this.$emit('prevent-add');
return;
}

console.log(1)

setTimeout(() => {
this.focused = true;
console.log(2, focus)
focus && setTimeout(() => {
console.log(3)
this.focus();
});
})

},


close() {
this.focused = false;
},


closeIfMouseOut() {
if (this.mouseOverWorkingPlace) {
return;
}
this.close();
},

},
watch: {
value(newValue){
Expand Down
19 changes: 19 additions & 0 deletions vue-tags-input/vue-tags-input.props.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,23 @@ export default {
default: true,
type: Boolean,
},
/**
* @description Show link <a>{{ placeholder }}</a> instead of <input :value="instead"> when input is unfocused
* @type {Boolean}
* @default false
*/
linkInsteadOfUnfocusedInput: {
default: false,
type: Boolean,
},

/**
* @description Prevent adding new tags
* @type {Boolean}
* @default false
*/
preventAdd: {
default: false,
type: Boolean,
},
};
5 changes: 5 additions & 0 deletions vue-tags-input/vue-tags-input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ div.vue-tags-input.disabled {
background-color: $primary;
color: #fff;
}

.ti-new-tab-button {
margin: 2px;
padding: 5px;
}
25 changes: 24 additions & 1 deletion vue-tags-input/vue-tags-input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
<div
class="vue-tags-input"
:class="[{ 'ti-disabled': disabled }, { 'ti-focus': focused }]"
@mousedown="closeIfMouseOut"
>
<div class="ti-input">
<ul v-if="tagsCopy" class="ti-tags">

<!-- Tag -->
<li
v-for="(tag, index) in tagsCopy"
:key="index"
Expand Down Expand Up @@ -118,8 +121,20 @@
/>
</div>
</li>



<!-- Input -->
<li class="ti-new-tag-input-wrapper">

<button
v-if="linkInsteadOfUnfocusedInput && !focused"
@click="open(true)"
class="ti-new-tab-button"
>{{ placeholder }}</button>

<input
v-else
ref="newTagInput"
v-bind="$attrs"
:class="[createClasses(newTag, tags, validation, isDuplicate)]"
Expand All @@ -142,15 +157,23 @@
@blur="$emit('blur', $event)"
@focus="focused = true; $emit('focus', $event)"
@click="addOnlyFromAutocomplete ? false : selectedItem = null"
>
@mouseenter="mouseOverWorkingPlace = true"
@mouseleave="mouseOverWorkingPlace = false"
/>

</li>
</ul>
</div>

<slot name="between-elements" />

<!-- Autocompletion -->
<div
v-if="autocompleteOpen"
class="ti-autocomplete"
@mouseout="selectedItem = null"
@mouseenter="mouseOverWorkingPlace = true"
@mouseleave="mouseOverWorkingPlace = false"
>
<slot name="autocomplete-header" />
<ul>
Expand Down