Commit 5e6413e3 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '350312-labels-widget-auto-select-first-label-when-searching' into 'master'

Labels widget - focus first item on search

See merge request gitlab-org/gitlab!78246
parents 3c4a68bf 2a376050
......@@ -84,6 +84,14 @@ export default {
showNoMatchingResultsMessage() {
return Boolean(this.searchKey) && this.visibleLabels.length === 0;
},
shouldHighlighFirstItem() {
return this.searchKey !== '' && this.visibleLabels.length > 0;
},
},
updated() {
if (this.shouldHighlighFirstItem) {
this.$refs.labelItem[0]?.$el?.firstChild?.focus();
}
},
methods: {
isLabelSelected(label) {
......@@ -143,11 +151,14 @@ export default {
/>
<template v-else>
<gl-dropdown-item
v-for="label in visibleLabels"
v-for="(label, index) in visibleLabels"
ref="labelItem"
:key="label.id"
:is-checked="isLabelSelected(label)"
:is-check-centered="true"
:is-check-item="true"
:active="shouldHighlighFirstItem && index === 0"
active-class="is-focused"
data-testid="labels-list"
@click.native.capture.stop="handleLabelClick(label)"
>
......
......@@ -110,6 +110,19 @@ describe('DropdownContentsLabelsView', () => {
});
});
it('first item is active when search is not empty', async () => {
createComponent({
queryHandler: jest.fn().mockResolvedValue(workspaceLabelsQueryResponse),
searchKey: 'Label',
});
await makeObserverAppear();
await waitForPromises();
await nextTick();
expect(findLabelsList().exists()).toBe(true);
expect(findFirstLabel().attributes('active')).toBe('true');
});
it('when search returns 0 results', async () => {
createComponent({
queryHandler: jest.fn().mockResolvedValue({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment