Skip to content
Merged
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
41 changes: 41 additions & 0 deletions cypress/component/NcSelectUsers.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { mount } from 'cypress/vue2'
import NcSelectUsers from '../../src/components/NcSelectUsers/NcSelectUsers.vue'

it('emits the search event', async () => {
const wrapper = mount(NcSelectUsers, {
propsData: {
ariaLabelCombobox: 'Search users',
options: [],
},
})

wrapper.get('input[type="search"]')
.type('query')

wrapper.then(({ wrapper }) => {
expect(wrapper.emitted('search')).to.eql([['query']])
})
})

it('also emits the search event if cleared', async () => {
const wrapper = mount(NcSelectUsers, {
propsData: {
ariaLabelCombobox: 'Search users',
options: [],
},
})

wrapper.get('input[type="search"]')
.type('query')
wrapper.get('input[type="search"]')
.type('{clearAll}')

wrapper.then(({ wrapper }) => {
expect(wrapper.emitted('search')).to.eql([['query', '']])
})
})
13 changes: 10 additions & 3 deletions src/components/NcSelectUsers/NcSelectUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ export default {
</docs>

<script setup>
import { ref } from 'vue'
import { ref, watch } from 'vue'
import { t } from '../../l10n.js'
import createElementId from '../../utils/GenRandomId.js'

import NcListItemIcon from '../NcListItemIcon/NcListItemIcon.vue'
import NcSelect from '../NcSelect/index.js'
import NcSelect from '../NcSelect/NcSelect.vue'

const props = defineProps({
/**
Expand Down Expand Up @@ -321,9 +321,16 @@ const props = defineProps({
},
})

defineEmits(['update:modelValue'])
const emit = defineEmits(['search', 'update:modelValue'])

const search = ref('')
watch(search, () => {
/**
* Emitted when the user enters some query.
* This can be used to asynchronously fetch more options.
*/
emit('search', search.value)
})

// Avatar size so the component has the same size as Nc*Field
const clickableArea = Number.parseInt(window.getComputedStyle(document.body).getPropertyValue('--default-clickable-area'))
Expand Down
Loading