Skip to content
代码片段 群组 项目
提交 7b89fec6 编辑于 作者: Eduardo Sanz García's avatar Eduardo Sanz García 提交者: Paul Gascou-Vaillancourt
浏览文件

Pass events to parent scope of GroupSelect

We use `v-on="$listeners"` to pass events to the parent scope.
`GroupSelect` becomes a transparent wrapper. Parent of `GroupSelect` can
listen to the `input` event, and any other events if added in the
future.
上级 b19d1944
No related branches found
No related tags found
无相关合并请求
...@@ -121,6 +121,7 @@ export default { ...@@ -121,6 +121,7 @@ export default {
:default-toggle-text="$options.i18n.toggleText" :default-toggle-text="$options.i18n.toggleText"
:fetch-items="fetchGroups" :fetch-items="fetchGroups"
:fetch-initial-selection-text="fetchGroupName" :fetch-initial-selection-text="fetchGroupName"
v-on="$listeners"
> >
<template #error> <template #error>
<gl-alert v-if="errorMessage" class="gl-mb-3" variant="danger" @dismiss="dismissError">{{ <gl-alert v-if="errorMessage" class="gl-mb-3" variant="danger" @dismiss="dismissError">{{
......
...@@ -166,6 +166,7 @@ export default { ...@@ -166,6 +166,7 @@ export default {
:fetch-initial-selection-text="fetchProjectName" :fetch-initial-selection-text="fetchProjectName"
:block="block" :block="block"
clearable clearable
v-on="$listeners"
> >
<template v-if="hasHtmlLabel" #label> <template v-if="hasHtmlLabel" #label>
<span v-safe-html="label"></span> <span v-safe-html="label"></span>
......
...@@ -39,6 +39,8 @@ describe('GroupSelect', () => { ...@@ -39,6 +39,8 @@ describe('GroupSelect', () => {
const findEntitySelect = () => wrapper.findComponent(EntitySelect); const findEntitySelect = () => wrapper.findComponent(EntitySelect);
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
const handleInput = jest.fn();
// Helpers // Helpers
const createComponent = ({ props = {} } = {}) => { const createComponent = ({ props = {} } = {}) => {
wrapper = shallowMountExtended(GroupSelect, { wrapper = shallowMountExtended(GroupSelect, {
...@@ -52,6 +54,9 @@ describe('GroupSelect', () => { ...@@ -52,6 +54,9 @@ describe('GroupSelect', () => {
GlAlert, GlAlert,
EntitySelect, EntitySelect,
}, },
listeners: {
input: handleInput,
},
}); });
}; };
const openListbox = () => findListbox().vm.$emit('shown'); const openListbox = () => findListbox().vm.$emit('shown');
...@@ -132,4 +137,11 @@ describe('GroupSelect', () => { ...@@ -132,4 +137,11 @@ describe('GroupSelect', () => {
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
expect(findAlert().text()).toBe(FETCH_GROUPS_ERROR); expect(findAlert().text()).toBe(FETCH_GROUPS_ERROR);
}); });
it('forwards events to the parent scope via `v-on="$listeners"`', () => {
createComponent();
findEntitySelect().vm.$emit('input');
expect(handleInput).toHaveBeenCalledTimes(1);
});
}); });
...@@ -45,6 +45,8 @@ describe('ProjectSelect', () => { ...@@ -45,6 +45,8 @@ describe('ProjectSelect', () => {
const findEntitySelect = () => wrapper.findComponent(EntitySelect); const findEntitySelect = () => wrapper.findComponent(EntitySelect);
const findAlert = () => wrapper.findComponent(GlAlert); const findAlert = () => wrapper.findComponent(GlAlert);
const handleInput = jest.fn();
// Helpers // Helpers
const createComponent = ({ props = {} } = {}) => { const createComponent = ({ props = {} } = {}) => {
wrapper = mountExtended(ProjectSelect, { wrapper = mountExtended(ProjectSelect, {
...@@ -59,6 +61,9 @@ describe('ProjectSelect', () => { ...@@ -59,6 +61,9 @@ describe('ProjectSelect', () => {
GlAlert, GlAlert,
EntitySelect, EntitySelect,
}, },
listeners: {
input: handleInput,
},
}); });
}; };
const openListbox = () => findListbox().vm.$emit('shown'); const openListbox = () => findListbox().vm.$emit('shown');
...@@ -255,4 +260,11 @@ describe('ProjectSelect', () => { ...@@ -255,4 +260,11 @@ describe('ProjectSelect', () => {
expect(findAlert().exists()).toBe(true); expect(findAlert().exists()).toBe(true);
expect(findAlert().text()).toBe(FETCH_PROJECTS_ERROR); expect(findAlert().text()).toBe(FETCH_PROJECTS_ERROR);
}); });
it('forwards events to the parent scope via `v-on="$listeners"`', () => {
createComponent();
findEntitySelect().vm.$emit('input');
expect(handleInput).toHaveBeenCalledTimes(1);
});
}); });
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册