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

Implement is-draggable feature #135

Open
wants to merge 3 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ add-tags-on-blur | Boolean | false | Add new tags when on the input is blur. The
sort-search-results | Boolean | true | Whether the search results should be sorted.
before-adding-tag | Function | `tag => true` | Callback to perform additional checks and actions before a tag is added. Return `true` to allow a tag to be added or `false` to forbid the action.
before-removing-tag | Function | `tag => true` | Callback to perform additional checks and actions before a tag is removed. Return `true` to allow a tag to be added or `false` to forbid the action.
is-draggable | Boolean | false | Enable draggable sorting of tags.

#### Events

Expand Down
11 changes: 10 additions & 1 deletion dist/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
width: 75%;
left: 0.15em;
background: #5dc282;

height: 2px;
margin-top: -1px;
}
Expand Down Expand Up @@ -102,6 +101,16 @@
background-color: #f0f1f2;
}

.tags-input-badge-draggable {
cursor: move;
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently supported by Chrome and Opera */
}

/* Typeahead */
.typeahead-hide-btn {
color: #999 !important;
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"dev": "cross-env NODE_ENV=development webpack-dev-server --open --hot",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
},
"dependencies": {},
"dependencies": {
"vuedraggable": "^2.24.3"
},
"browserslist": [
"> 1%",
"last 2 versions",
Expand Down
45 changes: 28 additions & 17 deletions src/VoerroTagsInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,26 @@
'active': isActive,
'disabled': disabled,
}">
<span v-for="(tag, index) in tags"
:key="index"
class="tags-input-badge tags-input-badge-pill tags-input-badge-selected-default"
:class="{ 'disabled': disabled }"
>
<slot name="selected-tag"
:tag="tag"
:index="index"
:removeTag="removeTag"
<draggable v-model="tags" :disabled='!isDraggable' @start="drag=true" @end="drag=false" style="width:100%;">
<span v-for="(tag, index) in tags"
:key="index"
class="tags-input-badge tags-input-badge-pill tags-input-badge-selected-default"
:class="[{ 'disabled': disabled }, { 'tags-input-badge-draggable': isDraggable }]"
>
<span v-html="tag[textField]"></span>

<a v-show="!disabled"
href="#"
class="tags-input-remove"
@click.prevent="removeTag(index)"></a>
</slot>
</span>
<slot name="selected-tag"
:tag="tag"
:index="index"
:removeTag="removeTag"
>
<span v-html="tag[textField]"></span>

<a v-show="!disabled"
href="#"
class="tags-input-remove"
@click.prevent="removeTag(index)"></a>
</slot>
</span>
</draggable>

<input type="text"
ref="taginput"
Expand Down Expand Up @@ -100,7 +102,11 @@
</template>

<script>
import draggable from 'vuedraggable'
export default {
components: {
draggable,
},
props: {
elementId: String,

Expand Down Expand Up @@ -269,6 +275,11 @@ export default {
type: Function,
default: () => true
},

isDraggable: {
type: Boolean,
default: false
},
},

data() {
Expand Down