Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
feat: expose remove function for tag slot
Browse files Browse the repository at this point in the history
ref: #235
  • Loading branch information
Ernest committed Jun 26, 2021
1 parent a91b89c commit 77f8f72
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
47 changes: 47 additions & 0 deletions cypress/integration/slots/tag/remove.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link
type="text/css"
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css"
/>
<link type="text/css" rel="stylesheet" href="/dist/index.css" />
<script src="https://unpkg.com/vue@next/dist/vue.global.prod.js"></script>
</head>

<body>
<div id="app"></div>
<script src="/dist/vue-next-select.iife.js"></script>
<script>
const { ref, createApp } = Vue
const app = createApp({
name: 'app',
setup() {
const selectedOptions = ref(['i'])
const options = ref(['i'])
return {
selectedOptions,
options,
}
},
template: `
<vue-select
v-model="selectedOptions"
:options="options"
multiple
taggable
>
<template #tag="{ option, remove }">
<button @click.stop="remove">{{ option }}</button>
</template>
</vue-select>
`,
})

app.component('vue-select', VueNextSelect)
app.mount(document.querySelector('#app'))
</script>
</body>
</html>
13 changes: 13 additions & 0 deletions cypress/integration/slots/tag/remove.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference types="cypress" />
import path from 'path'

context('tag', () => {
it('should expose remove function', () => {
cy.visit(path.join(__dirname, 'remove.html'))
cy.get('.vue-tag.selected').should('have.length', 1)

cy.get('.vue-tag.selected').click()

cy.get('.vue-tag.selected').should('have.length', 0)
})
})
1 change: 1 addition & 0 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ New in `2.6.0+`
- **Attributes**:

- `{OptionType}` option
- `{Function}` remove

### toggle

Expand Down
2 changes: 1 addition & 1 deletion src/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<template v-if="multiple && taggable">
<v-tags :modelValue="optionsWithInfo" :collapse-tags="collapseTags" tabindex="-1" @click="focus">
<template #default="{ option }">
<slot name="tag" :option="option.originalOption">
<slot name="tag" :option="option.originalOption" :remove="() => addOrRemoveOption($event, option)">
<span>{{ option.label }}</span>
<img
src="./images/delete.svg"
Expand Down

0 comments on commit 77f8f72

Please sign in to comment.