@gitlab/ui 56.0.1 → 56.1.1

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
+ ## [56.1.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v56.1.0...v56.1.1) (2023-02-20)
2
+
3
+
4
+ ### Performance Improvements
5
+
6
+ * **GlCollapsibleDropdown:** avoid unnecessary loop ([2d13b6e](https://gitlab.com/gitlab-org/gitlab-ui/commit/2d13b6ecc80154e70a4d637974b8434d50e53928))
7
+
8
+ # [56.1.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v56.0.1...v56.1.0) (2023-02-20)
9
+
10
+
11
+ ### Features
12
+
13
+ * **GlDisclosureDropdown, GlCollapsibleListbox:** Set focus on the first custom toggle's child ([2a86c03](https://gitlab.com/gitlab-org/gitlab-ui/commit/2a86c035d0b92ead9bc15017521a205977ad6d2e))
14
+
1
15
  ## [56.0.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v56.0.0...v56.0.1) (2023-02-17)
2
16
 
3
17
 
@@ -2,6 +2,7 @@ import _uniqueId from 'lodash/uniqueId';
2
2
  import { createPopper } from '@popperjs/core';
3
3
  import { buttonCategoryOptions, dropdownVariantOptions, buttonSizeOptions, dropdownPlacements } from '../../../../utils/constants';
4
4
  import { POPPER_CONFIG, GL_DROPDOWN_SHOWN, GL_DROPDOWN_HIDDEN, ENTER, SPACE } from '../constants';
5
+ import { isElementFocusable, isElementTabbable, logWarning } from '../../../../utils/utils';
5
6
  import GlButton from '../../button/button';
6
7
  import GlIcon from '../../icon/icon';
7
8
  import { OutsideDirective } from '../../../../directives/outside/outside';
@@ -116,6 +117,14 @@ var script = {
116
117
  var _this$toggleText;
117
118
  return Boolean(this.icon && (!((_this$toggleText = this.toggleText) !== null && _this$toggleText !== void 0 && _this$toggleText.length) || this.textSrOnly));
118
119
  },
120
+ ariaAttributes() {
121
+ return {
122
+ 'aria-haspopup': this.ariaHaspopup,
123
+ 'aria-expanded': this.visible,
124
+ 'aria-controls': this.baseDropdownId,
125
+ 'aria-labelledby': this.toggleLabelledBy
126
+ };
127
+ },
119
128
  toggleButtonClasses() {
120
129
  return [this.toggleClass, {
121
130
  'gl-new-dropdown-toggle': true,
@@ -145,6 +154,7 @@ var script = {
145
154
  disabled: this.disabled,
146
155
  loading: this.loading,
147
156
  class: this.toggleButtonClasses,
157
+ ...this.ariaAttributes,
148
158
  listeners: {
149
159
  click: () => this.toggle()
150
160
  }
@@ -152,9 +162,7 @@ var script = {
152
162
  }
153
163
  return {
154
164
  is: 'div',
155
- role: 'button',
156
165
  class: 'gl-new-dropdown-custom-toggle',
157
- tabindex: '0',
158
166
  listeners: {
159
167
  keydown: event => this.onKeydown(event),
160
168
  click: () => this.toggle()
@@ -162,7 +170,8 @@ var script = {
162
170
  };
163
171
  },
164
172
  toggleElement() {
165
- return this.$refs.toggle.$el || this.$refs.toggle;
173
+ var _this$$refs$toggle;
174
+ return this.$refs.toggle.$el || ((_this$$refs$toggle = this.$refs.toggle) === null || _this$$refs$toggle === void 0 ? void 0 : _this$$refs$toggle.firstElementChild);
166
175
  },
167
176
  popperConfig() {
168
177
  return {
@@ -171,15 +180,34 @@ var script = {
171
180
  };
172
181
  }
173
182
  },
183
+ watch: {
184
+ ariaAttributes: {
185
+ deep: true,
186
+ handler(ariaAttributes) {
187
+ if (this.$scopedSlots.toggle) {
188
+ Object.keys(ariaAttributes).forEach(key => {
189
+ this.toggleElement.setAttribute(key, ariaAttributes[key]);
190
+ });
191
+ }
192
+ }
193
+ }
194
+ },
174
195
  mounted() {
175
196
  this.$nextTick(() => {
176
197
  this.popper = createPopper(this.toggleElement, this.$refs.content, this.popperConfig);
177
198
  });
199
+ this.checkToggleFocusable();
178
200
  },
179
201
  beforeDestroy() {
180
202
  this.popper.destroy();
181
203
  },
182
204
  methods: {
205
+ checkToggleFocusable() {
206
+ if (!isElementFocusable(this.toggleElement) && !isElementTabbable(this.toggleElement)) {
207
+ logWarning(`GlDisclosureDropdown/GlCollapsibleListbox: Toggle is missing a 'tabindex' and cannot be focused.
208
+ Use 'a' or 'button' element instead or make sure to add 'role="button"' along with 'tabindex' otherwise.`);
209
+ }
210
+ },
183
211
  async toggle() {
184
212
  this.visible = !this.visible;
185
213
  if (this.visible) {
@@ -238,7 +266,7 @@ var script = {
238
266
  const __vue_script__ = script;
239
267
 
240
268
  /* template */
241
- var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{directives:[{name:"outside",rawName:"v-outside",value:(_vm.close),expression:"close"}],staticClass:"gl-new-dropdown",class:{ 'gl-display-block!': _vm.block }},[_c(_vm.toggleOptions.is,_vm._g(_vm._b({ref:"toggle",tag:"component",attrs:{"id":_vm.toggleId,"data-testid":"base-dropdown-toggle","aria-haspopup":_vm.ariaHaspopup,"aria-expanded":_vm.visible,"aria-labelledby":_vm.toggleLabelledBy,"aria-controls":_vm.baseDropdownId}},'component',_vm.toggleOptions,false),_vm.toggleOptions.listeners),[_vm._t("toggle",function(){return [_c('span',{staticClass:"gl-new-dropdown-button-text",class:{ 'gl-sr-only': _vm.textSrOnly }},[_vm._v("\n "+_vm._s(_vm.toggleText)+"\n ")]),_vm._v(" "),(!_vm.noCaret)?_c('gl-icon',{staticClass:"gl-button-icon gl-new-dropdown-chevron",attrs:{"name":"chevron-down"}}):_vm._e()]})],2),_vm._v(" "),_c('div',{ref:"content",staticClass:"gl-new-dropdown-panel",class:{ 'gl-display-block!': _vm.visible },attrs:{"id":_vm.baseDropdownId,"data-testid":"base-dropdown-menu"},on:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }$event.stopPropagation();$event.preventDefault();return _vm.closeAndFocus.apply(null, arguments)}}},[_c('div',{staticClass:"gl-new-dropdown-inner"},[_vm._t("default")],2)])],1)};
269
+ var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',{directives:[{name:"outside",rawName:"v-outside",value:(_vm.close),expression:"close"}],staticClass:"gl-new-dropdown",class:{ 'gl-display-block!': _vm.block }},[_c(_vm.toggleOptions.is,_vm._g(_vm._b({ref:"toggle",tag:"component",attrs:{"id":_vm.toggleId,"data-testid":"base-dropdown-toggle"}},'component',_vm.toggleOptions,false),_vm.toggleOptions.listeners),[_vm._t("toggle",function(){return [_c('span',{staticClass:"gl-new-dropdown-button-text",class:{ 'gl-sr-only': _vm.textSrOnly }},[_vm._v("\n "+_vm._s(_vm.toggleText)+"\n ")]),_vm._v(" "),(!_vm.noCaret)?_c('gl-icon',{staticClass:"gl-button-icon gl-new-dropdown-chevron",attrs:{"name":"chevron-down"}}):_vm._e()]})],2),_vm._v(" "),_c('div',{ref:"content",staticClass:"gl-new-dropdown-panel",class:{ 'gl-display-block!': _vm.visible },attrs:{"id":_vm.baseDropdownId,"data-testid":"base-dropdown-menu"},on:{"keydown":function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"esc",27,$event.key,["Esc","Escape"])){ return null; }$event.stopPropagation();$event.preventDefault();return _vm.closeAndFocus.apply(null, arguments)}}},[_c('div',{staticClass:"gl-new-dropdown-inner"},[_vm._t("default")],2)])],1)};
242
270
  var __vue_staticRenderFns__ = [];
243
271
 
244
272
  /* style */
@@ -25,7 +25,11 @@ const hasOnlyListItems = _ref => {
25
25
  return false;
26
26
  }
27
27
  const nodes = defaultSlot();
28
- return Array.isArray(nodes) && nodes.filter(vNode => vNode.tag).length && (nodes.filter(vNode => vNode.tag).every(isValidSlotTagVue2) || nodes.filter(vNode => vNode.tag).every(isValidSlotTag));
28
+ if (!Array.isArray(nodes)) {
29
+ return false;
30
+ }
31
+ const tags = nodes.filter(vNode => vNode.tag);
32
+ return tags.length && tags.every(tag => isValidSlotTag(tag) || isValidSlotTagVue2(tag));
29
33
  };
30
34
 
31
35
  export { hasOnlyListItems, isGroup, isItem, itemsValidator };