Skip to content

Commit

Permalink
Added @clear event #68
Browse files Browse the repository at this point in the history
  • Loading branch information
adamberecz committed May 17, 2021
1 parent 0fc297d commit 0da5c07
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ mounted() {
| **@search-change** | `query` | Emitted after a character is typed. |
| **@select** | `option` | Emitted after an option or tag is selected. |
| **@tag** | `query` | Emitted after enter is hit when a new tag is being created. |
| **@clear** | | Emitted when the options are cleared. |

## Slots

Expand Down
1 change: 1 addition & 0 deletions src/composables/useOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export default function useOptions (props, context, dep)
}

const clear = () => {
context.emit('clear')
update(nullValue.value)
}

Expand Down
13 changes: 13 additions & 0 deletions tests/unit/composables/useOptions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,19 @@ describe('useOptions', () => {

expect(getValue(select)).toStrictEqual([])
})

it('should emit clear event', async () => {
let select = createSelect({
options: [1,2,3],
value: 1,
})

select.vm.clear()

await nextTick()

expect(select.emitted('clear')).toBeTruthy()
})
})

describe('isSelected', () => {
Expand Down

0 comments on commit 0da5c07

Please sign in to comment.