@gitlab/ui 42.17.0 → 42.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # [42.18.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v42.17.0...v42.18.0) (2022-07-11)
2
+
3
+
4
+ ### Features
5
+
6
+ * **GlCombobox:** Add action items ([297ed28](https://gitlab.com/gitlab-org/gitlab-ui/commit/297ed28588558229d0e2e5629875e80ec52edc32))
7
+ * **GlCombobox:** Add action items ([af4eba0](https://gitlab.com/gitlab-org/gitlab-ui/commit/af4eba02c5345e6709ef0359feeeed63659acb27))
8
+ * **GlCombobox:** Add action items ([cae7a7e](https://gitlab.com/gitlab-org/gitlab-ui/commit/cae7a7ecc7552cda29c41eb7c04dd3c59db1be0c))
9
+
1
10
  # [42.17.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v42.16.0...v42.17.0) (2022-07-08)
2
11
 
3
12
 
@@ -37,5 +37,19 @@ const objectTokenList = [{
37
37
  id: '12',
38
38
  title: 'xenarthra'
39
39
  }];
40
+ const oneTokenList = ['dog'];
41
+ const actionsList = [{
42
+ label: 'Create',
43
+ fn: () => {
44
+ // eslint-disable-next-line no-alert
45
+ window.alert('Create action');
46
+ }
47
+ }, {
48
+ label: 'Edit',
49
+ fn: () => {
50
+ // eslint-disable-next-line no-alert
51
+ window.alert('Edit action');
52
+ }
53
+ }];
40
54
 
41
- export { labelText, objectTokenList, stringTokenList };
55
+ export { actionsList, labelText, objectTokenList, oneTokenList, stringTokenList };
@@ -1,5 +1,6 @@
1
1
  import _uniqueId from 'lodash/uniqueId';
2
2
  import GlDropdownItem from '../../dropdown/dropdown_item';
3
+ import GlDropdownDivider from '../../dropdown/dropdown_divider';
3
4
  import GlFormGroup from '../form_group/form_group';
4
5
  import GlFormInput from '../form_input/form_input';
5
6
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
@@ -8,6 +9,7 @@ var script = {
8
9
  name: 'GlFormCombobox',
9
10
  components: {
10
11
  GlDropdownItem,
12
+ GlDropdownDivider,
11
13
  GlFormGroup,
12
14
  GlFormInput
13
15
  },
@@ -29,6 +31,15 @@ var script = {
29
31
  type: Array,
30
32
  required: true
31
33
  },
34
+
35
+ /**
36
+ * List of action functions to display at the bottom of the dropdown
37
+ */
38
+ actionList: {
39
+ type: Array,
40
+ required: false,
41
+ default: () => []
42
+ },
32
43
  value: {
33
44
  type: [String, Object],
34
45
  required: true
@@ -65,11 +76,39 @@ var script = {
65
76
  },
66
77
 
67
78
  showSuggestions() {
68
- return this.results.length > 0;
79
+ return this.value.length > 0 && this.allItems.length > 0;
69
80
  },
70
81
 
71
82
  displayedValue() {
72
83
  return this.matchValueToAttr && this.value[this.matchValueToAttr] ? this.value[this.matchValueToAttr] : this.value;
84
+ },
85
+
86
+ resultsLength() {
87
+ return this.results.length;
88
+ },
89
+
90
+ allItems() {
91
+ return [...this.results, ...this.actionList];
92
+ }
93
+
94
+ },
95
+ watch: {
96
+ tokenList(newList) {
97
+ const filteredTokens = newList.filter(token => {
98
+ if (this.matchValueToAttr) {
99
+ // For API driven tokens, we don't need extra filtering
100
+ return token;
101
+ }
102
+
103
+ return token.toLowerCase().includes(this.value.toLowerCase());
104
+ });
105
+
106
+ if (filteredTokens.length) {
107
+ this.openSuggestions(filteredTokens);
108
+ } else {
109
+ this.results = [];
110
+ this.arrowCounter = -1;
111
+ }
73
112
  }
74
113
 
75
114
  },
@@ -86,6 +125,7 @@ var script = {
86
125
  closeSuggestions() {
87
126
  this.results = [];
88
127
  this.arrowCounter = -1;
128
+ this.userDismissedResults = true;
89
129
  },
90
130
 
91
131
  handleClickOutside(event) {
@@ -95,30 +135,41 @@ var script = {
95
135
  },
96
136
 
97
137
  onArrowDown() {
138
+ var _this$$refs$results$n;
139
+
98
140
  const newCount = this.arrowCounter + 1;
99
141
 
100
- if (newCount >= this.results.length) {
142
+ if (newCount >= this.allItems.length) {
101
143
  this.arrowCounter = 0;
102
144
  return;
103
145
  }
104
146
 
105
147
  this.arrowCounter = newCount;
148
+ (_this$$refs$results$n = this.$refs.results[newCount]) === null || _this$$refs$results$n === void 0 ? void 0 : _this$$refs$results$n.$el.scrollIntoView(false);
106
149
  },
107
150
 
108
151
  onArrowUp() {
152
+ var _this$$refs$results$n2;
153
+
109
154
  const newCount = this.arrowCounter - 1;
110
155
 
111
156
  if (newCount < 0) {
112
- this.arrowCounter = this.results.length - 1;
157
+ this.arrowCounter = this.allItems.length - 1;
113
158
  return;
114
159
  }
115
160
 
116
161
  this.arrowCounter = newCount;
162
+ (_this$$refs$results$n2 = this.$refs.results[newCount]) === null || _this$$refs$results$n2 === void 0 ? void 0 : _this$$refs$results$n2.$el.scrollIntoView(true);
117
163
  },
118
164
 
119
165
  onEnter() {
120
- const currentToken = this.results[this.arrowCounter] || this.value;
121
- this.selectToken(currentToken);
166
+ const focusedItem = this.allItems[this.arrowCounter] || this.value;
167
+
168
+ if (focusedItem.fn) {
169
+ this.selectAction(focusedItem);
170
+ } else {
171
+ this.selectToken(focusedItem);
172
+ }
122
173
  },
123
174
 
124
175
  onEsc() {
@@ -127,7 +178,6 @@ var script = {
127
178
  }
128
179
 
129
180
  this.closeSuggestions();
130
- this.userDismissedResults = true;
131
181
  },
132
182
 
133
183
  onEntry(value) {
@@ -150,7 +200,8 @@ var script = {
150
200
  if (filteredTokens.length) {
151
201
  this.openSuggestions(filteredTokens);
152
202
  } else {
153
- this.closeSuggestions();
203
+ this.results = [];
204
+ this.arrowCounter = -1;
154
205
  }
155
206
  },
156
207
 
@@ -167,6 +218,12 @@ var script = {
167
218
  */
168
219
 
169
220
  this.$emit('value-selected', value);
221
+ },
222
+
223
+ selectAction(value) {
224
+ value.fn();
225
+ this.$emit('input', this.value);
226
+ this.closeSuggestions();
170
227
  }
171
228
 
172
229
  }
@@ -176,7 +233,7 @@ var script = {
176
233
  const __vue_script__ = script;
177
234
 
178
235
  /* template */
179
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-form-combobox dropdown",attrs:{"role":"combobox","aria-owns":_vm.suggestionsId,"aria-expanded":_vm.ariaExpanded}},[_c('gl-form-group',{attrs:{"label":_vm.labelText,"label-for":_vm.inputId,"label-sr-only":_vm.labelSrOnly}},[_c('gl-form-input',{attrs:{"id":_vm.inputId,"value":_vm.displayedValue,"type":"text","role":"searchbox","autocomplete":_vm.showAutocomplete,"aria-autocomplete":"list","aria-controls":_vm.suggestionsId,"aria-haspopup":"listbox","autofocus":_vm.autofocus},on:{"input":_vm.onEntry,"keydown":[function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"down",40,$event.key,["Down","ArrowDown"])){ return null; }return _vm.onArrowDown($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"up",38,$event.key,["Up","ArrowUp"])){ return null; }return _vm.onArrowUp($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }$event.preventDefault();return _vm.onEnter($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }$event.stopPropagation();return _vm.onEsc($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"tab",9,$event.key,"Tab")){ return null; }return _vm.closeSuggestions($event)}]}})],1),_vm._v(" "),_c('ul',{directives:[{name:"show",rawName:"v-show",value:(_vm.showSuggestions && !_vm.userDismissedResults),expression:"showSuggestions && !userDismissedResults"}],staticClass:"dropdown-menu dropdown-full-width gl-list-style-none gl-pl-0 gl-mb-0 gl-overflow-y-auto",class:{ 'show-dropdown': _vm.showSuggestions },attrs:{"id":_vm.suggestionsId,"data-testid":"combobox-dropdown"}},_vm._l((_vm.results),function(result,i){return _c('gl-dropdown-item',{key:i,class:{ 'highlight-dropdown': i === _vm.arrowCounter },attrs:{"role":"option","aria-selected":i === _vm.arrowCounter,"tabindex":"-1"},on:{"click":function($event){return _vm.selectToken(result)}}},[_vm._t("result",[_vm._v(_vm._s(result))],{"item":result})],2)}),1)],1)};
236
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"gl-form-combobox dropdown",attrs:{"role":"combobox","aria-owns":_vm.suggestionsId,"aria-expanded":_vm.ariaExpanded}},[_c('gl-form-group',{attrs:{"label":_vm.labelText,"label-for":_vm.inputId,"label-sr-only":_vm.labelSrOnly}},[_c('gl-form-input',{attrs:{"id":_vm.inputId,"value":_vm.displayedValue,"type":"text","role":"searchbox","autocomplete":_vm.showAutocomplete,"aria-autocomplete":"list","aria-controls":_vm.suggestionsId,"aria-haspopup":"listbox","autofocus":_vm.autofocus},on:{"input":_vm.onEntry,"keydown":[function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"down",40,$event.key,["Down","ArrowDown"])){ return null; }return _vm.onArrowDown($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"up",38,$event.key,["Up","ArrowUp"])){ return null; }return _vm.onArrowUp($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }$event.preventDefault();return _vm.onEnter($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }$event.stopPropagation();return _vm.onEsc($event)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"tab",9,$event.key,"Tab")){ return null; }return _vm.closeSuggestions($event)}]}})],1),_vm._v(" "),_c('ul',{directives:[{name:"show",rawName:"v-show",value:(_vm.showSuggestions && !_vm.userDismissedResults),expression:"showSuggestions && !userDismissedResults"}],staticClass:"dropdown-menu dropdown-full-width show-dropdown gl-list-style-none gl-pl-0 gl-mb-0 gl-display-flex gl-flex-direction-column",attrs:{"id":_vm.suggestionsId,"data-testid":"combobox-dropdown"}},[_c('li',{staticClass:"gl-overflow-y-auto show-dropdown"},[_c('ul',{staticClass:"gl-list-style-none gl-pl-0 gl-mb-0"},_vm._l((_vm.results),function(result,i){return _c('gl-dropdown-item',{key:i,ref:"results",refInFor:true,class:{ 'gl-bg-gray-50': i === _vm.arrowCounter },attrs:{"role":"option","aria-selected":i === _vm.arrowCounter,"tabindex":"-1"},on:{"click":function($event){return _vm.selectToken(result)}}},[_vm._t("result",[_vm._v(_vm._s(result))],{"item":result})],2)}),1)]),_vm._v(" "),(_vm.resultsLength > 0 && _vm.actionList.length > 0)?_c('gl-dropdown-divider'):_vm._e(),_vm._v(" "),_c('li',[_c('ul',{staticClass:"gl-list-style-none gl-pl-0 gl-mb-0"},_vm._l((_vm.actionList),function(action,i){return _c('gl-dropdown-item',{key:i + _vm.resultsLength,class:{ 'gl-bg-gray-50': i + _vm.resultsLength === _vm.arrowCounter },attrs:{"role":"option","aria-selected":i + _vm.resultsLength === _vm.arrowCounter,"tabindex":"-1","data-testid":"combobox-action"},on:{"click":function($event){return _vm.selectAction(action)}}},[_vm._t("action",[_vm._v(_vm._s(action.label))],{"item":action})],2)}),1)])],1)],1)};
180
237
  var __vue_staticRenderFns__ = [];
181
238
 
182
239
  /* style */