@gitlab/ui 87.2.0 → 87.3.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,17 @@
1
+ # [87.3.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v87.2.1...v87.3.0) (2024-07-30)
2
+
3
+
4
+ ### Features
5
+
6
+ * **GlTokenSelector:** Add `showAddNewAlways` prop ([89ae31c](https://gitlab.com/gitlab-org/gitlab-ui/commit/89ae31c903054f2b1866a692772799d94299e76c))
7
+
8
+ ## [87.2.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v87.2.0...v87.2.1) (2024-07-28)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * action-neutral-foreground design token description ([55de73f](https://gitlab.com/gitlab-org/gitlab-ui/commit/55de73f3848651e7561718eab29036f3f0253338))
14
+
1
15
  # [87.2.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v87.1.2...v87.2.0) (2024-07-26)
2
16
 
3
17
 
@@ -34,6 +34,14 @@ var script = {
34
34
  required: false,
35
35
  default: false
36
36
  },
37
+ /**
38
+ * Shows 'Add new token option' in dropdown even if results are present, requires allowUserDefinedTokens to be true
39
+ */
40
+ showAddNewAlways: {
41
+ type: Boolean,
42
+ required: false,
43
+ default: false
44
+ },
37
45
  /**
38
46
  * Dropdown items are loading, can be used when requesting new dropdown items
39
47
  */
@@ -158,7 +166,10 @@ var script = {
158
166
  return !this.filteredDropdownItems.length;
159
167
  },
160
168
  userDefinedTokenCanBeAdded() {
161
- return this.allowUserDefinedTokens && this.dropdownHasNoItems && this.inputText !== '';
169
+ if (!this.allowUserDefinedTokens || !this.inputText) {
170
+ return false;
171
+ }
172
+ return this.showAddNewAlways || this.dropdownHasNoItems;
162
173
  },
163
174
  hideDropdown() {
164
175
  if (this.userDefinedTokenCanBeAdded) {
@@ -250,9 +261,7 @@ var script = {
250
261
  });
251
262
  },
252
263
  handleEnter() {
253
- if (this.userDefinedTokenCanBeAdded) {
254
- this.addToken();
255
- } else if (this.focusedDropdownItem && this.dropdownIsOpen) {
264
+ if (this.focusedDropdownItem && this.dropdownIsOpen) {
256
265
  this.addToken(this.focusedDropdownItem);
257
266
  }
258
267
  },
@@ -290,19 +299,13 @@ var script = {
290
299
  }
291
300
  this.focusTextInput();
292
301
  },
293
- addToken() {
294
- let dropdownItem = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
295
- const token = dropdownItem !== null ? dropdownItem : {
296
- id: uniqueId('user-defined-token'),
297
- name: this.inputText
298
- };
299
-
302
+ addToken(dropdownItem) {
300
303
  /**
301
304
  * Fired when a token is added or removed
302
305
  *
303
306
  * @property {array} selectedTokens
304
307
  */
305
- this.$emit('input', [...this.selectedTokens, token]);
308
+ this.$emit('input', [...this.selectedTokens, dropdownItem]);
306
309
  this.inputText = '';
307
310
  this.closeDropdown();
308
311
 
@@ -311,13 +314,13 @@ var script = {
311
314
  *
312
315
  * @property {object} token
313
316
  */
314
- this.$emit('token-add', token);
317
+ this.$emit('token-add', dropdownItem);
315
318
  },
316
319
  removeToken(token) {
317
320
  /**
318
- * Fired when user types in the token selector
321
+ * Fired when a token is added or removed
319
322
  *
320
- * @property {string} inputText
323
+ * @property {array} selectedTokens
321
324
  */
322
325
  this.$emit('input', this.selectedTokens.filter(selectedToken => selectedToken.id !== token.id));
323
326
  /**
@@ -366,7 +369,7 @@ const __vue_script__ = script;
366
369
  /* template */
367
370
  var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('div',{ref:"container",staticClass:"gl-token-selector gl-form-input form-control form-control-plaintext gl-flex !gl-cursor-text gl-items-center !gl-px-3 !gl-py-2",class:[_vm.inputFocused ? 'gl-token-selector-focus-glow' : '', _vm.containerClass, _vm.stateClass],on:{"click":_vm.handleContainerClick}},[(_vm.showEmptyPlaceholder)?_vm._t("empty-placeholder"):_vm._e(),_vm._v(" "),_c('gl-token-container',{attrs:{"tokens":_vm.selectedTokens,"state":_vm.state,"register-focus-on-token":_vm.registerFocusOnToken,"view-only":_vm.viewOnly,"show-clear-all-button":_vm.showClearAllButton},on:{"token-remove":_vm.removeToken,"cancel-focus":_vm.cancelTokenFocus,"clear-all":_vm.clearAll},scopedSlots:_vm._u([{key:"token-content",fn:function(ref){
368
371
  var token = ref.token;
369
- return [_vm._t("token-content",null,{"token":token})]}},{key:"text-input",fn:function(){return [_c('input',_vm._b({ref:"textInput",staticClass:"gl-token-selector-input gl-h-auto gl-w-4/10 gl-grow gl-border-none gl-bg-transparent gl-px-1 gl-font-regular gl-text-base gl-leading-normal gl-text-gray-900 gl-outline-none",attrs:{"type":"text","autocomplete":_vm.autocomplete,"aria-labelledby":_vm.ariaLabelledby,"placeholder":_vm.placeholder,"disabled":_vm.viewOnly},domProps:{"value":_vm.inputText},on:{"input":function($event){_vm.inputText = $event.target.value;},"focus":_vm.handleFocus,"blur":_vm.handleBlur,"keydown":[function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }return _vm.handleEnter.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }return _vm.handleEscape.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"delete",[8,46],$event.key,["Backspace","Delete","Del"])){ return null; }return _vm.handleBackspace.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"up",38,$event.key,["Up","ArrowUp"])){ return null; }$event.preventDefault();return _vm.dropdownEventHandlers.handleUpArrow.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"down",40,$event.key,["Down","ArrowDown"])){ return null; }$event.preventDefault();return _vm.dropdownEventHandlers.handleDownArrow.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"home",undefined,$event.key,undefined)){ return null; }return _vm.dropdownEventHandlers.handleHomeKey.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"end",undefined,$event.key,undefined)){ return null; }return _vm.dropdownEventHandlers.handleEndKey.apply(null, arguments)},function($event){$event.stopPropagation();return _vm.$emit('keydown', $event)}],"click":_vm.handleInputClick}},'input',_vm.textInputAttrs,false))]},proxy:true}],null,true)})],2),_vm._v(" "),_c('gl-token-selector-dropdown',{attrs:{"menu-class":_vm.menuClass,"show":_vm.dropdownIsOpen,"loading":_vm.loading,"dropdown-items":_vm.filteredDropdownItems,"selected-tokens":_vm.selectedTokens,"input-text":_vm.inputText,"allow-user-defined-tokens":_vm.allowUserDefinedTokens,"component-id":_vm.$options.componentId,"register-dropdown-event-handlers":_vm.registerDropdownEventHandlers,"register-reset-focused-dropdown-item":_vm.registerResetFocusedDropdownItem},on:{"dropdown-item-click":_vm.addToken,"show":_vm.openDropdown},scopedSlots:_vm._u([{key:"loading-content",fn:function(){return [_vm._t("loading-content")]},proxy:true},{key:"user-defined-token-content",fn:function(){return [_vm._t("user-defined-token-content",null,{"inputText":_vm.inputText})]},proxy:true},{key:"no-results-content",fn:function(){return [_vm._t("no-results-content")]},proxy:true},{key:"dropdown-item-content",fn:function(ref){
372
+ return [_vm._t("token-content",null,{"token":token})]}},{key:"text-input",fn:function(){return [_c('input',_vm._b({ref:"textInput",staticClass:"gl-token-selector-input gl-h-auto gl-w-4/10 gl-grow gl-border-none gl-bg-transparent gl-px-1 gl-font-regular gl-text-base gl-leading-normal gl-text-gray-900 gl-outline-none",attrs:{"type":"text","autocomplete":_vm.autocomplete,"aria-labelledby":_vm.ariaLabelledby,"placeholder":_vm.placeholder,"disabled":_vm.viewOnly},domProps:{"value":_vm.inputText},on:{"input":function($event){_vm.inputText = $event.target.value;},"focus":_vm.handleFocus,"blur":_vm.handleBlur,"keydown":[function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }return _vm.handleEnter.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }return _vm.handleEscape.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"delete",[8,46],$event.key,["Backspace","Delete","Del"])){ return null; }return _vm.handleBackspace.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"up",38,$event.key,["Up","ArrowUp"])){ return null; }$event.preventDefault();return _vm.dropdownEventHandlers.handleUpArrow.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"down",40,$event.key,["Down","ArrowDown"])){ return null; }$event.preventDefault();return _vm.dropdownEventHandlers.handleDownArrow.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"home",undefined,$event.key,undefined)){ return null; }return _vm.dropdownEventHandlers.handleHomeKey.apply(null, arguments)},function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"end",undefined,$event.key,undefined)){ return null; }return _vm.dropdownEventHandlers.handleEndKey.apply(null, arguments)},function($event){$event.stopPropagation();return _vm.$emit('keydown', $event)}],"click":_vm.handleInputClick}},'input',_vm.textInputAttrs,false))]},proxy:true}],null,true)})],2),_vm._v(" "),_c('gl-token-selector-dropdown',{attrs:{"menu-class":_vm.menuClass,"show":_vm.dropdownIsOpen,"loading":_vm.loading,"dropdown-items":_vm.filteredDropdownItems,"selected-tokens":_vm.selectedTokens,"input-text":_vm.inputText,"user-defined-token-can-be-added":_vm.userDefinedTokenCanBeAdded,"component-id":_vm.$options.componentId,"register-dropdown-event-handlers":_vm.registerDropdownEventHandlers,"register-reset-focused-dropdown-item":_vm.registerResetFocusedDropdownItem},on:{"dropdown-item-click":_vm.addToken,"show":_vm.openDropdown},scopedSlots:_vm._u([{key:"loading-content",fn:function(){return [_vm._t("loading-content")]},proxy:true},{key:"user-defined-token-content",fn:function(){return [_vm._t("user-defined-token-content",null,{"inputText":_vm.inputText})]},proxy:true},{key:"no-results-content",fn:function(){return [_vm._t("no-results-content")]},proxy:true},{key:"dropdown-item-content",fn:function(ref){
370
373
  var dropdownItem = ref.dropdownItem;
371
374
  return [_vm._t("dropdown-item-content",null,{"dropdownItem":dropdownItem})]}},{key:"dropdown-footer",fn:function(){return [_vm._t("dropdown-footer")]},proxy:true}],null,true),model:{value:(_vm.focusedDropdownItem),callback:function ($$v) {_vm.focusedDropdownItem=$$v;},expression:"focusedDropdownItem"}})],1)};
372
375
  var __vue_staticRenderFns__ = [];
@@ -1,3 +1,4 @@
1
+ import uniqueId from 'lodash/uniqueId';
1
2
  import GlDropdownItem from '../dropdown/dropdown_item';
2
3
  import { tokensValidator } from './helpers';
3
4
  import __vue_normalize__ from 'vue-runtime-helpers/dist/normalize-component.js';
@@ -32,7 +33,7 @@ var script = {
32
33
  type: String,
33
34
  required: true
34
35
  },
35
- allowUserDefinedTokens: {
36
+ userDefinedTokenCanBeAdded: {
36
37
  type: Boolean,
37
38
  required: true
38
39
  },
@@ -55,7 +56,27 @@ var script = {
55
56
  };
56
57
  },
57
58
  computed: {
59
+ userDefinedToken() {
60
+ return {
61
+ id: uniqueId('user-defined-token'),
62
+ name: this.inputText
63
+ };
64
+ },
65
+ dropdownLength() {
66
+ // Adds an additional dropdown item for the 'Add ... dropdown' item
67
+ return this.userDefinedTokenCanBeAdded ? this.dropdownItems.length : this.dropdownItems.length - 1;
68
+ },
69
+ focusedLastDropdownItem() {
70
+ return this.focusedDropdownItemIndex === this.dropdownLength;
71
+ },
72
+ focusedUserDefinedToken() {
73
+ // User defined tokens are always the last in the list
74
+ return this.userDefinedTokenCanBeAdded && this.focusedLastDropdownItem;
75
+ },
58
76
  focusedDropdownItem() {
77
+ if (this.focusedUserDefinedToken) {
78
+ return this.userDefinedToken;
79
+ }
59
80
  return this.dropdownItems[this.focusedDropdownItemIndex];
60
81
  }
61
82
  },
@@ -93,7 +114,7 @@ var script = {
93
114
  handleMousedown(dropdownItem) {
94
115
  // `event.relatedTarget` returns `null` on Safari because buttons are not focused on click (https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus)
95
116
  // Because of this we need to manually focus on the button. We do this in `mousedown` because it is fired before the `blur` event
96
- const dropdownItemRef = dropdownItem === null ? this.$refs.userDefinedTokenDropdownItem : this.getDropdownItemRef(dropdownItem);
117
+ const dropdownItemRef = this.getDropdownItemRef(dropdownItem);
97
118
  if (dropdownItemRef !== null && dropdownItemRef !== void 0 && dropdownItemRef.$el) {
98
119
  dropdownItemRef.$el.querySelector('button').focus();
99
120
  }
@@ -116,7 +137,7 @@ var script = {
116
137
  }
117
138
 
118
139
  // Last dropdown item has been reached
119
- if (this.focusedDropdownItemIndex === this.dropdownItems.length - 1) {
140
+ if (this.focusedLastDropdownItem) {
120
141
  return;
121
142
  }
122
143
  this.focusNextDropdownItem();
@@ -130,7 +151,7 @@ var script = {
130
151
  this.focusLastDropdownItem();
131
152
  },
132
153
  focusLastDropdownItem() {
133
- this.focusedDropdownItemIndex = this.dropdownItems.length - 1;
154
+ this.focusedDropdownItemIndex = this.dropdownLength;
134
155
  },
135
156
  focusFirstDropdownItem() {
136
157
  this.focusedDropdownItemIndex = 0;
@@ -152,6 +173,9 @@ var script = {
152
173
  },
153
174
  getDropdownItemRef(dropdownItem) {
154
175
  var _this$$refs$dropdownI;
176
+ if (this.focusedUserDefinedToken) {
177
+ return this.$refs[this.userDefinedToken.id];
178
+ }
155
179
  return (_this$$refs$dropdownI = this.$refs.dropdownItems) === null || _this$$refs$dropdownI === void 0 ? void 0 : _this$$refs$dropdownI.find(ref => ref.$attrs['data-dropdown-item-id'] === dropdownItem.id);
156
180
  },
157
181
  dropdownItemIdAttribute(dropdownItem) {
@@ -164,7 +188,7 @@ var script = {
164
188
  const __vue_script__ = script;
165
189
 
166
190
  /* template */
167
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"dropdown b-dropdown gl-dropdown gl-relative",class:{ show: _vm.show }},[_c('ul',{ref:"dropdownMenu",staticClass:"dropdown-menu gl-absolute",class:[{ show: _vm.show }, _vm.menuClass],attrs:{"role":"menu","aria-activedescendant":_vm.dropdownItemIdAttribute(_vm.focusedDropdownItem)}},[(_vm.loading)?_c('gl-dropdown-item',{attrs:{"disabled":""}},[_vm._t("loading-content",function(){return [_vm._v("Searching...")]})],2):(_vm.dropdownItems.length)?_vm._l((_vm.dropdownItems),function(dropdownItem){return _c('gl-dropdown-item',{key:dropdownItem.id,ref:"dropdownItems",refInFor:true,attrs:{"id":_vm.dropdownItemIdAttribute(dropdownItem),"data-dropdown-item-id":dropdownItem.id,"active":_vm.dropdownItemIsFocused(dropdownItem),"active-class":"is-focused","tabindex":"-1"},on:{"click":function($event){return _vm.handleDropdownItemClick(dropdownItem)}}},[_c('div',{staticClass:"-gl-mx-4 -gl-my-3 gl-px-4 gl-py-3",on:{"mousedown":function($event){return _vm.handleMousedown(dropdownItem)}}},[_vm._t("dropdown-item-content",function(){return [_vm._v("\n "+_vm._s(dropdownItem.name)+"\n ")]},{"dropdownItem":dropdownItem})],2)])}):[(_vm.allowUserDefinedTokens && _vm.inputText !== '')?_c('gl-dropdown-item',{ref:"userDefinedTokenDropdownItem",attrs:{"active":"","active-class":"is-focused"},on:{"click":function($event){return _vm.handleDropdownItemClick(null)}}},[_c('div',{staticClass:"-gl-mx-4 -gl-my-3 gl-px-4 gl-py-3",on:{"mousedown":function($event){return _vm.handleMousedown(null)}}},[_vm._t("user-defined-token-content",function(){return [_vm._v("\n Add \""+_vm._s(_vm.inputText)+"\"\n ")]},{"inputText":_vm.inputText})],2)]):_c('gl-dropdown-item',{attrs:{"disabled":""}},[_vm._t("no-results-content",function(){return [_vm._v("No matches found")]})],2)],_vm._v(" "),_vm._t("dropdown-footer")],2)])};
191
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{staticClass:"dropdown b-dropdown gl-dropdown gl-relative",class:{ show: _vm.show }},[_c('ul',{ref:"dropdownMenu",staticClass:"dropdown-menu gl-absolute",class:[{ show: _vm.show }, _vm.menuClass],attrs:{"role":"menu","aria-activedescendant":_vm.dropdownItemIdAttribute(_vm.focusedDropdownItem)}},[(_vm.loading)?_c('gl-dropdown-item',{attrs:{"disabled":""}},[_vm._t("loading-content",function(){return [_vm._v("Searching...")]})],2):_vm._e(),_vm._v(" "),_vm._l((_vm.dropdownItems),function(dropdownItem){return _c('gl-dropdown-item',{key:dropdownItem.id,ref:"dropdownItems",refInFor:true,attrs:{"id":_vm.dropdownItemIdAttribute(dropdownItem),"data-dropdown-item-id":dropdownItem.id,"active":_vm.dropdownItemIsFocused(dropdownItem),"active-class":"is-focused","tabindex":"-1"},on:{"click":function($event){return _vm.handleDropdownItemClick(dropdownItem)}}},[_c('div',{staticClass:"-gl-mx-4 -gl-my-3 gl-px-4 gl-py-3",on:{"mousedown":function($event){return _vm.handleMousedown(dropdownItem)}}},[_vm._t("dropdown-item-content",function(){return [_vm._v("\n "+_vm._s(dropdownItem.name)+"\n ")]},{"dropdownItem":dropdownItem})],2)])}),_vm._v(" "),(_vm.userDefinedTokenCanBeAdded)?_c('gl-dropdown-item',{ref:_vm.userDefinedToken.id,attrs:{"id":_vm.dropdownItemIdAttribute(_vm.userDefinedToken),"data-dropdown-item-id":_vm.userDefinedToken.id,"active":_vm.dropdownItemIsFocused(_vm.userDefinedToken),"active-class":"is-focused","tabindex":"-1"},on:{"click":function($event){return _vm.handleDropdownItemClick(_vm.userDefinedToken)}}},[_c('div',{staticClass:"-gl-mx-4 -gl-my-3 gl-px-4 gl-py-3",on:{"mousedown":function($event){return _vm.handleMousedown(_vm.userDefinedToken)}}},[_vm._t("user-defined-token-content",function(){return [_vm._v("\n Add \""+_vm._s(_vm.inputText)+"\"\n ")]},{"inputText":_vm.inputText})],2)]):(!_vm.dropdownItems.length)?_c('gl-dropdown-item',{attrs:{"disabled":""}},[_vm._t("no-results-content",function(){return [_vm._v("No matches found")]})],2):_vm._e(),_vm._v(" "),_vm._t("dropdown-footer")],2)])};
168
192
  var __vue_staticRenderFns__ = [];
169
193
 
170
194
  /* style */