Skip to content

Commit 6ca7c8b

Browse files
authored
feat(InputMenu): emit remove-tag event (#4511)
1 parent bb99345 commit 6ca7c8b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/runtime/components/InputMenu.vue

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,16 @@ export interface InputMenuProps<T extends ArrayOrNested<InputMenuItem> = ArrayOr
128128
}
129129
130130
export type InputMenuEmits<A extends ArrayOrNested<InputMenuItem>, VK extends GetItemKeys<A> | undefined, M extends boolean> = Pick<ComboboxRootEmits, 'update:open'> & {
131-
change: [payload: Event]
132-
blur: [payload: FocusEvent]
133-
focus: [payload: FocusEvent]
134-
create: [item: string]
131+
'change': [payload: Event]
132+
'blur': [payload: FocusEvent]
133+
'focus': [payload: FocusEvent]
134+
'create': [item: string]
135135
/** Event handler when highlighted element changes. */
136-
highlight: [payload: {
136+
'highlight': [payload: {
137137
ref: HTMLElement
138138
value: GetModelValue<A, VK, M>
139139
} | undefined]
140+
'remove-tag': [item: GetModelValue<A, VK, M>]
140141
} & GetModelValueEmits<A, VK, M>
141142
142143
type SlotProps<T extends InputMenuItem> = (props: { item: T, index: number }) => any
@@ -366,6 +367,7 @@ function onRemoveTag(event: any) {
366367
const modelValue = props.modelValue as GetModelValue<T, VK, true>
367368
const filteredValue = modelValue.filter(value => !isEqual(value, event))
368369
emits('update:modelValue', filteredValue as GetModelValue<T, VK, M>)
370+
emits('remove-tag', event)
369371
onUpdate(filteredValue)
370372
}
371373
}

test/components/InputMenu.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@ describe('InputMenu', () => {
108108
await input.vm.$emit('update:open', false)
109109
expect(wrapper.emitted()).toMatchObject({ blur: [[{ type: 'blur' }]] })
110110
})
111+
112+
test('remove-tag event', async () => {
113+
const wrapper = mount(InputMenu, { props: { modelValue: ['Option 1'], items: ['Option 1', 'Option 2'], multiple: true } })
114+
const input = wrapper.findComponent({ name: 'TagsInputRoot' })
115+
await input.vm.$emit('remove-tag', 'Option 1')
116+
expect(wrapper.emitted()).toMatchObject({ 'remove-tag': [['Option 1']] })
117+
})
111118
})
112119

113120
describe('form integration', async () => {

0 commit comments

Comments
 (0)