@gitlab/ui 54.3.0 → 54.4.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 +14 -0
- package/dist/components/base/new_dropdowns/constants.js +3 -3
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown.js +3 -3
- package/dist/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.js +5 -2
- package/dist/components/base/new_dropdowns/disclosure/mock_data.js +7 -0
- package/dist/components/base/new_dropdowns/listbox/listbox.js +1 -1
- package/dist/utils/utils.js +9 -1
- package/package.json +3 -3
- package/src/components/base/new_dropdowns/constants.js +3 -3
- package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown.md +21 -13
- package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown.spec.js +20 -0
- package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown.vue +3 -3
- package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.spec.js +50 -0
- package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown_item.vue +6 -3
- package/src/components/base/new_dropdowns/disclosure/mock_data.js +8 -0
- package/src/components/base/new_dropdowns/listbox/listbox.spec.js +22 -0
- package/src/components/base/new_dropdowns/listbox/listbox.vue +1 -0
- package/src/scss/fonts.scss +2 -2
- package/src/utils/utils.js +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [54.4.1](https://gitlab.com/gitlab-org/gitlab-ui/compare/v54.4.0...v54.4.1) (2023-02-06)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **GlListbox:** Stop listbox ENTER event prop ([944b7f9](https://gitlab.com/gitlab-org/gitlab-ui/commit/944b7f9baf67fc71787d14d614fb51b722083820))
|
|
7
|
+
|
|
8
|
+
# [54.4.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v54.3.0...v54.4.0) (2023-02-02)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **GlDisclosureDropdown:** Add support for item wrapper class ([8b575af](https://gitlab.com/gitlab-org/gitlab-ui/commit/8b575af03dcdeb9206ef3caf65f2519b9628b1ae))
|
|
14
|
+
|
|
1
15
|
# [54.3.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v54.2.3...v54.3.0) (2023-02-02)
|
|
2
16
|
|
|
3
17
|
|
|
@@ -12,11 +12,11 @@ const GL_DROPDOWN_SHOWN = 'shown';
|
|
|
12
12
|
const GL_DROPDOWN_HIDDEN = 'hidden';
|
|
13
13
|
|
|
14
14
|
// KEY Codes
|
|
15
|
-
const HOME = 'Home';
|
|
16
|
-
const END = 'End';
|
|
17
|
-
const ARROW_UP = 'ArrowUp';
|
|
18
15
|
const ARROW_DOWN = 'ArrowDown';
|
|
16
|
+
const ARROW_UP = 'ArrowUp';
|
|
17
|
+
const END = 'End';
|
|
19
18
|
const ENTER = 'Enter';
|
|
19
|
+
const HOME = 'Home';
|
|
20
20
|
const SPACE = 'Space';
|
|
21
21
|
|
|
22
22
|
export { ARROW_DOWN, ARROW_UP, END, ENTER, GL_DROPDOWN_HIDDEN, GL_DROPDOWN_SHOWN, HOME, POPPER_CONFIG, SPACE };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _uniqueId from 'lodash/uniqueId';
|
|
2
2
|
import _clamp from 'lodash/clamp';
|
|
3
|
-
import { stopEvent } from '../../../../utils/utils';
|
|
3
|
+
import { stopEvent, filterVisible } from '../../../../utils/utils';
|
|
4
4
|
import { GL_DROPDOWN_SHOWN, GL_DROPDOWN_HIDDEN, HOME, END, ARROW_UP, ARROW_DOWN } from '../constants';
|
|
5
5
|
import { buttonCategoryOptions, dropdownVariantOptions, buttonSizeOptions, dropdownPlacements } from '../../../../utils/constants';
|
|
6
6
|
import GlBaseDropdown from '../base_dropdown/base_dropdown';
|
|
@@ -104,7 +104,7 @@ var script = {
|
|
|
104
104
|
toggleId: {
|
|
105
105
|
type: String,
|
|
106
106
|
required: false,
|
|
107
|
-
default:
|
|
107
|
+
default: _uniqueId('dropdown-toggle-btn-')
|
|
108
108
|
},
|
|
109
109
|
/**
|
|
110
110
|
* Additional CSS classes to customize toggle appearance
|
|
@@ -231,7 +231,7 @@ var script = {
|
|
|
231
231
|
getFocusableListItemElements() {
|
|
232
232
|
var _this$$refs$content;
|
|
233
233
|
const items = (_this$$refs$content = this.$refs.content) === null || _this$$refs$content === void 0 ? void 0 : _this$$refs$content.querySelectorAll(`.${ITEM_CLASS}`);
|
|
234
|
-
return Array.from(items || []);
|
|
234
|
+
return filterVisible(Array.from(items || []));
|
|
235
235
|
},
|
|
236
236
|
focusNextItem(event, elements, offset) {
|
|
237
237
|
const {
|
|
@@ -26,12 +26,14 @@ var script = {
|
|
|
26
26
|
const {
|
|
27
27
|
item
|
|
28
28
|
} = this;
|
|
29
|
+
if (!item) return null;
|
|
29
30
|
if (this.isLink) return {
|
|
30
31
|
is: 'a',
|
|
31
32
|
attrs: {
|
|
32
33
|
href: item.href,
|
|
33
34
|
...item.extraAttrs
|
|
34
35
|
},
|
|
36
|
+
wrapperClass: item.wrapperClass,
|
|
35
37
|
listeners: {}
|
|
36
38
|
};
|
|
37
39
|
return {
|
|
@@ -45,7 +47,8 @@ var script = {
|
|
|
45
47
|
var _item$action;
|
|
46
48
|
return (_item$action = item.action) === null || _item$action === void 0 ? void 0 : _item$action.call(undefined, item);
|
|
47
49
|
}
|
|
48
|
-
}
|
|
50
|
+
},
|
|
51
|
+
wrapperClass: item.wrapperClass
|
|
49
52
|
};
|
|
50
53
|
}
|
|
51
54
|
},
|
|
@@ -78,7 +81,7 @@ var script = {
|
|
|
78
81
|
const __vue_script__ = script;
|
|
79
82
|
|
|
80
83
|
/* template */
|
|
81
|
-
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('li',{
|
|
84
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('li',{class:[_vm.$options.ITEM_CLASS, _vm.itemComponent && _vm.itemComponent.wrapperClass],attrs:{"tabindex":"0","data-testid":"disclosure-dropdown-item"},on:{"click":_vm.action,"keydown":_vm.onKeydown}},[(_vm.isCustomContent)?_c('div',{staticClass:"gl-new-dropdown-item-content"},[_c('div',{staticClass:"gl-new-dropdown-item-text-wrapper"},[_vm._t("default")],2)]):(_vm.itemComponent && _vm.item)?[_c(_vm.itemComponent.is,_vm._g(_vm._b({ref:"item",tag:"component",staticClass:"gl-new-dropdown-item-content",attrs:{"tabindex":"-1"}},'component',_vm.itemComponent.attrs,false),_vm.itemComponent.listeners),[_c('span',{staticClass:"gl-new-dropdown-item-text-wrapper"},[_vm._v("\n "+_vm._s(_vm.item.text)+"\n ")])])]:_vm._e()],2)};
|
|
82
85
|
var __vue_staticRenderFns__ = [];
|
|
83
86
|
|
|
84
87
|
/* style */
|
|
@@ -41,6 +41,13 @@ const mockItemsCustomItem = [{
|
|
|
41
41
|
target: '_blank',
|
|
42
42
|
rel: 'nofollow'
|
|
43
43
|
}
|
|
44
|
+
}, {
|
|
45
|
+
text: 'I am only visible on mobile!',
|
|
46
|
+
action: () => {
|
|
47
|
+
// eslint-disable-next-line no-console
|
|
48
|
+
console.log('clicked!');
|
|
49
|
+
},
|
|
50
|
+
wrapperClass: 'gl-sm-display-none!'
|
|
44
51
|
}];
|
|
45
52
|
const mockGroupsCustomItem = [{
|
|
46
53
|
name: 'Merge requests',
|
|
@@ -536,7 +536,7 @@ var script = {
|
|
|
536
536
|
const __vue_script__ = script;
|
|
537
537
|
|
|
538
538
|
/* template */
|
|
539
|
-
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('gl-base-dropdown',{ref:"baseDropdown",attrs:{"aria-haspopup":"listbox","aria-labelledby":_vm.toggleAriaLabelledBy,"block":_vm.block,"toggle-id":_vm.toggleId,"toggle-text":_vm.listboxToggleText,"toggle-class":_vm.toggleClass,"text-sr-only":_vm.textSrOnly,"category":_vm.category,"variant":_vm.variant,"size":_vm.size,"icon":_vm.icon,"disabled":_vm.disabled,"loading":_vm.loading,"no-caret":_vm.noCaret,"placement":_vm.placement},on:_vm._d({},[_vm.$options.events.GL_DROPDOWN_SHOWN,_vm.onShow,_vm.$options.events.GL_DROPDOWN_HIDDEN,_vm.onHide]),scopedSlots:_vm._u([(_vm.hasCustomToggle)?{key:"toggle",fn:function(){return [_vm._t("toggle")]},proxy:true}:null],null,true)},[_vm._v(" "),(_vm.headerText)?_c('div',{staticClass:"gl-display-flex gl-align-items-center gl-p-4! gl-min-h-8",class:_vm.$options.HEADER_ITEMS_BORDER_CLASSES},[_c('div',{staticClass:"gl-flex-grow-1 gl-font-weight-bold gl-font-sm gl-pr-2",attrs:{"id":_vm.headerId,"data-testid":"listbox-header-text"}},[_vm._v("\n "+_vm._s(_vm.headerText)+"\n ")]),_vm._v(" "),(_vm.showResetButton)?_c('gl-button',{staticClass:"gl-focus-inset-border-2-blue-400! gl-flex-shrink-0 gl-font-sm! gl-px-2! gl-py-2! gl-w-auto! gl-m-0!",attrs:{"category":"tertiary","data-testid":"listbox-reset-button"},on:{"click":_vm.onResetButtonClicked}},[_vm._v("\n "+_vm._s(_vm.resetButtonLabel)+"\n ")]):_vm._e()],1):_vm._e(),_vm._v(" "),(_vm.searchable)?_c('div',{class:_vm.$options.HEADER_ITEMS_BORDER_CLASSES},[_c('gl-listbox-search-input',{ref:"searchBox",attrs:{"aria-owns":_vm.listboxId,"data-testid":"listbox-search-input","placeholder":_vm.searchPlaceholder},on:{"input":_vm.search,"keydown":_vm.onKeydown},model:{value:(_vm.searchStr),callback:function ($$v) {_vm.searchStr=$$v;},expression:"searchStr"}}),_vm._v(" "),(_vm.searching)?_c('gl-loading-icon',{staticClass:"gl-my-3",attrs:{"data-testid":"listbox-search-loader","size":"md"}}):_vm._e()],1):_vm._e(),_vm._v(" "),(_vm.showList)?_c(_vm.listboxTag,{ref:"list",tag:"component",staticClass:"gl-new-dropdown-contents",attrs:{"id":_vm.listboxId,"aria-labelledby":_vm.listAriaLabelledBy || _vm.headerId || _vm.toggleId,"role":"listbox","tabindex":"-1"},on:{"keydown":_vm.onKeydown}},[_vm._l((_vm.items),function(item,index){return [(_vm.isOption(item))?[_c('gl-listbox-item',_vm._b({key:item.value,attrs:{"data-testid":("listbox-item-" + (item.value)),"is-selected":_vm.isSelected(item),"is-focused":_vm.isFocused(item),"is-check-centered":_vm.isCheckCentered},on:{"select":function($event){return _vm.onSelect(item, $event)}}},'gl-listbox-item',_vm.listboxItemMoreItemsAriaAttributes(index),false),[_vm._t("list-item",function(){return [_vm._v("\n "+_vm._s(item.text)+"\n ")]},{"item":item})],2)]:[_c('gl-listbox-group',{key:item.text,class:_vm.groupClasses(index),attrs:{"name":item.text},scopedSlots:_vm._u([(_vm.$scopedSlots['group-label'])?{key:"group-label",fn:function(){return [_vm._t("group-label",null,{"group":item})]},proxy:true}:null],null,true)},[_vm._v(" "),_vm._l((item.options),function(option){return _c('gl-listbox-item',{key:option.value,attrs:{"data-testid":("listbox-item-" + (option.value)),"is-selected":_vm.isSelected(option),"is-focused":_vm.isFocused(option),"is-check-centered":_vm.isCheckCentered},on:{"select":function($event){return _vm.onSelect(option, $event)}}},[_vm._t("list-item",function(){return [_vm._v("\n "+_vm._s(option.text)+"\n ")]},{"item":option})],2)})],2)]]}),_vm._v(" "),(_vm.infiniteScrollLoading)?_c(_vm.listboxTag === 'ul' ? 'li' : 'div',{tag:"component"},[_c('gl-loading-icon',{staticClass:"gl-my-3",attrs:{"data-testid":"listbox-infinite-scroll-loader","size":"md"}})],1):_vm._e(),_vm._v(" "),(_vm.showIntersectionObserver)?_c('gl-intersection-observer',{on:{"appear":_vm.onIntersectionObserverAppear}}):_vm._e()],2):_vm._e(),_vm._v(" "),(_vm.announceSRSearchResults)?_c('span',{staticClass:"gl-sr-only",attrs:{"data-testid":"listbox-number-of-results","aria-live":"assertive"}},[_vm._t("search-summary-sr-only")],2):(_vm.showNoResultsText)?_c('div',{staticClass:"gl-pl-7 gl-pr-5 gl-py-3 gl-font-base gl-text-gray-600",attrs:{"aria-live":"assertive","data-testid":"listbox-no-results-text"}},[_vm._v("\n "+_vm._s(_vm.noResultsText)+"\n ")]):_vm._e(),_vm._v(" "),_vm._t("footer")],2)};
|
|
539
|
+
var __vue_render__ = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('gl-base-dropdown',{ref:"baseDropdown",attrs:{"aria-haspopup":"listbox","aria-labelledby":_vm.toggleAriaLabelledBy,"block":_vm.block,"toggle-id":_vm.toggleId,"toggle-text":_vm.listboxToggleText,"toggle-class":_vm.toggleClass,"text-sr-only":_vm.textSrOnly,"category":_vm.category,"variant":_vm.variant,"size":_vm.size,"icon":_vm.icon,"disabled":_vm.disabled,"loading":_vm.loading,"no-caret":_vm.noCaret,"placement":_vm.placement},on:_vm._d({},[_vm.$options.events.GL_DROPDOWN_SHOWN,_vm.onShow,_vm.$options.events.GL_DROPDOWN_HIDDEN,_vm.onHide]),scopedSlots:_vm._u([(_vm.hasCustomToggle)?{key:"toggle",fn:function(){return [_vm._t("toggle")]},proxy:true}:null],null,true)},[_vm._v(" "),(_vm.headerText)?_c('div',{staticClass:"gl-display-flex gl-align-items-center gl-p-4! gl-min-h-8",class:_vm.$options.HEADER_ITEMS_BORDER_CLASSES},[_c('div',{staticClass:"gl-flex-grow-1 gl-font-weight-bold gl-font-sm gl-pr-2",attrs:{"id":_vm.headerId,"data-testid":"listbox-header-text"}},[_vm._v("\n "+_vm._s(_vm.headerText)+"\n ")]),_vm._v(" "),(_vm.showResetButton)?_c('gl-button',{staticClass:"gl-focus-inset-border-2-blue-400! gl-flex-shrink-0 gl-font-sm! gl-px-2! gl-py-2! gl-w-auto! gl-m-0!",attrs:{"category":"tertiary","data-testid":"listbox-reset-button"},on:{"click":_vm.onResetButtonClicked}},[_vm._v("\n "+_vm._s(_vm.resetButtonLabel)+"\n ")]):_vm._e()],1):_vm._e(),_vm._v(" "),(_vm.searchable)?_c('div',{class:_vm.$options.HEADER_ITEMS_BORDER_CLASSES},[_c('gl-listbox-search-input',{ref:"searchBox",attrs:{"aria-owns":_vm.listboxId,"data-testid":"listbox-search-input","placeholder":_vm.searchPlaceholder},on:{"input":_vm.search,"keydown":[function($event){if(!$event.type.indexOf('key')&&_vm._k($event.keyCode,"enter",13,$event.key,"Enter")){ return null; }$event.preventDefault();},_vm.onKeydown]},model:{value:(_vm.searchStr),callback:function ($$v) {_vm.searchStr=$$v;},expression:"searchStr"}}),_vm._v(" "),(_vm.searching)?_c('gl-loading-icon',{staticClass:"gl-my-3",attrs:{"data-testid":"listbox-search-loader","size":"md"}}):_vm._e()],1):_vm._e(),_vm._v(" "),(_vm.showList)?_c(_vm.listboxTag,{ref:"list",tag:"component",staticClass:"gl-new-dropdown-contents",attrs:{"id":_vm.listboxId,"aria-labelledby":_vm.listAriaLabelledBy || _vm.headerId || _vm.toggleId,"role":"listbox","tabindex":"-1"},on:{"keydown":_vm.onKeydown}},[_vm._l((_vm.items),function(item,index){return [(_vm.isOption(item))?[_c('gl-listbox-item',_vm._b({key:item.value,attrs:{"data-testid":("listbox-item-" + (item.value)),"is-selected":_vm.isSelected(item),"is-focused":_vm.isFocused(item),"is-check-centered":_vm.isCheckCentered},on:{"select":function($event){return _vm.onSelect(item, $event)}}},'gl-listbox-item',_vm.listboxItemMoreItemsAriaAttributes(index),false),[_vm._t("list-item",function(){return [_vm._v("\n "+_vm._s(item.text)+"\n ")]},{"item":item})],2)]:[_c('gl-listbox-group',{key:item.text,class:_vm.groupClasses(index),attrs:{"name":item.text},scopedSlots:_vm._u([(_vm.$scopedSlots['group-label'])?{key:"group-label",fn:function(){return [_vm._t("group-label",null,{"group":item})]},proxy:true}:null],null,true)},[_vm._v(" "),_vm._l((item.options),function(option){return _c('gl-listbox-item',{key:option.value,attrs:{"data-testid":("listbox-item-" + (option.value)),"is-selected":_vm.isSelected(option),"is-focused":_vm.isFocused(option),"is-check-centered":_vm.isCheckCentered},on:{"select":function($event){return _vm.onSelect(option, $event)}}},[_vm._t("list-item",function(){return [_vm._v("\n "+_vm._s(option.text)+"\n ")]},{"item":option})],2)})],2)]]}),_vm._v(" "),(_vm.infiniteScrollLoading)?_c(_vm.listboxTag === 'ul' ? 'li' : 'div',{tag:"component"},[_c('gl-loading-icon',{staticClass:"gl-my-3",attrs:{"data-testid":"listbox-infinite-scroll-loader","size":"md"}})],1):_vm._e(),_vm._v(" "),(_vm.showIntersectionObserver)?_c('gl-intersection-observer',{on:{"appear":_vm.onIntersectionObserverAppear}}):_vm._e()],2):_vm._e(),_vm._v(" "),(_vm.announceSRSearchResults)?_c('span',{staticClass:"gl-sr-only",attrs:{"data-testid":"listbox-number-of-results","aria-live":"assertive"}},[_vm._t("search-summary-sr-only")],2):(_vm.showNoResultsText)?_c('div',{staticClass:"gl-pl-7 gl-pr-5 gl-py-3 gl-font-base gl-text-gray-600",attrs:{"aria-live":"assertive","data-testid":"listbox-no-results-text"}},[_vm._v("\n "+_vm._s(_vm.noResultsText)+"\n ")]):_vm._e(),_vm._v(" "),_vm._t("footer")],2)};
|
|
540
540
|
var __vue_staticRenderFns__ = [];
|
|
541
541
|
|
|
542
542
|
/* style */
|
package/dist/utils/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isVisible } from 'bootstrap-vue/esm/utils/dom';
|
|
1
2
|
import { COMMA, labelColorOptions, focusableTags } from './constants';
|
|
2
3
|
|
|
3
4
|
function debounceByAnimationFrame(fn) {
|
|
@@ -134,4 +135,11 @@ function stopEvent(event) {
|
|
|
134
135
|
}
|
|
135
136
|
}
|
|
136
137
|
|
|
137
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Return an Array of visible items
|
|
140
|
+
*/
|
|
141
|
+
function filterVisible(els) {
|
|
142
|
+
return (els || []).filter(isVisible);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { colorFromBackground, debounceByAnimationFrame, filterVisible, focusFirstFocusableElement, hexToRgba, isDev, isElementFocusable, logWarning, rgbFromHex, rgbFromString, stopEvent, throttle, uid };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitlab/ui",
|
|
3
|
-
"version": "54.
|
|
3
|
+
"version": "54.4.1",
|
|
4
4
|
"description": "GitLab UI Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"clean": "rm -r dist storybook scss_to_js/scss_variables.* src/scss/utilities.scss",
|
|
30
30
|
"cy:run": "cypress run --browser firefox",
|
|
31
31
|
"start": "yarn storybook",
|
|
32
|
-
"storybook": "yarn storybook-prep && start-storybook --ci --host localhost --port 9001 -c .storybook
|
|
32
|
+
"storybook": "yarn storybook-prep && start-storybook --ci --host localhost --port 9001 -c .storybook",
|
|
33
33
|
"storybook-prep": "run-s generate-utilities build-scss-variables copy-fonts",
|
|
34
|
-
"storybook-static": "yarn storybook-prep && build-storybook -c .storybook -o storybook
|
|
34
|
+
"storybook-static": "yarn storybook-prep && build-storybook -c .storybook -o storybook",
|
|
35
35
|
"pretest:unit": "yarn build-scss-variables",
|
|
36
36
|
"test": "run-s test:unit test:visual",
|
|
37
37
|
"test:integration": "NODE_ENV=test start-server-and-test start http://localhost:9001 cy:run",
|
|
@@ -14,9 +14,9 @@ export const GL_DROPDOWN_SHOWN = 'shown';
|
|
|
14
14
|
export const GL_DROPDOWN_HIDDEN = 'hidden';
|
|
15
15
|
|
|
16
16
|
// KEY Codes
|
|
17
|
-
export const HOME = 'Home';
|
|
18
|
-
export const END = 'End';
|
|
19
|
-
export const ARROW_UP = 'ArrowUp';
|
|
20
17
|
export const ARROW_DOWN = 'ArrowDown';
|
|
18
|
+
export const ARROW_UP = 'ArrowUp';
|
|
19
|
+
export const END = 'End';
|
|
21
20
|
export const ENTER = 'Enter';
|
|
21
|
+
export const HOME = 'Home';
|
|
22
22
|
export const SPACE = 'Space';
|
|
@@ -5,10 +5,7 @@ to make sure this is the right dropdown component for you.
|
|
|
5
5
|
### Basic usage
|
|
6
6
|
|
|
7
7
|
```html
|
|
8
|
-
<gl-disclosure-dropdown-dropdown
|
|
9
|
-
toggle-text="Actions"
|
|
10
|
-
:items="items"
|
|
11
|
-
/>
|
|
8
|
+
<gl-disclosure-dropdown-dropdown toggle-text="Actions" :items="items" />
|
|
12
9
|
```
|
|
13
10
|
|
|
14
11
|
### Icon-only disclosure dropdown
|
|
@@ -58,17 +55,28 @@ Below are the expected shapes of these objects:
|
|
|
58
55
|
|
|
59
56
|
```typescript
|
|
60
57
|
type Item = {
|
|
61
|
-
text
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
// The item text
|
|
59
|
+
text: string;
|
|
60
|
+
// href link
|
|
61
|
+
href?: string;
|
|
62
|
+
// Item action
|
|
63
|
+
action?: (item: Item) => void;
|
|
64
|
+
// Set of extra attributes applied directly to the element
|
|
65
|
+
extraAttrs?: Object;
|
|
66
|
+
// Additional class/classes applied to the item wrapper
|
|
67
|
+
wrapperClass?: string;
|
|
68
|
+
};
|
|
65
69
|
|
|
66
70
|
type Group = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
// Name of the group, used as a header
|
|
72
|
+
name?: string;
|
|
73
|
+
// Items of the group
|
|
74
|
+
items: Array<Item>;
|
|
75
|
+
// Set of extra attributes applied directly to the element
|
|
76
|
+
extraAttrs?: Object;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
type ItemsProp = Array<Item> | Array<Group>;
|
|
72
80
|
```
|
|
73
81
|
|
|
74
82
|
#### Actions/links
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mount } from '@vue/test-utils';
|
|
2
|
+
import * as utils from '../../../../utils/utils';
|
|
2
3
|
import GlBaseDropdown from '../base_dropdown/base_dropdown.vue';
|
|
3
4
|
import {
|
|
4
5
|
GL_DROPDOWN_SHOWN,
|
|
@@ -32,6 +33,8 @@ describe('GlDisclosureDropdown', () => {
|
|
|
32
33
|
const findDisclosureGroups = () => wrapper.findAllComponents(GlDisclosureDropdownGroup);
|
|
33
34
|
const findListItem = (index) => findDisclosureItems().at(index).findComponent(ITEM_SELECTOR);
|
|
34
35
|
|
|
36
|
+
jest.spyOn(utils, 'filterVisible').mockImplementation((items) => items);
|
|
37
|
+
|
|
35
38
|
describe('toggle text', () => {
|
|
36
39
|
it('should pass toggle text to the base dropdown', () => {
|
|
37
40
|
const toggleText = 'Merge requests';
|
|
@@ -147,6 +150,23 @@ describe('GlDisclosureDropdown', () => {
|
|
|
147
150
|
await thirdItem.trigger('keydown', { code: HOME });
|
|
148
151
|
expect(firstItem.element).toHaveFocus();
|
|
149
152
|
});
|
|
153
|
+
|
|
154
|
+
describe('when an element is hidden', () => {
|
|
155
|
+
beforeEach(() => {
|
|
156
|
+
jest.spyOn(utils, 'filterVisible').mockReturnValue([firstItem.element, thirdItem.element]);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('should skip over it', async () => {
|
|
160
|
+
expect(firstItem.element).toHaveFocus();
|
|
161
|
+
await firstItem.trigger('keydown', { code: ARROW_DOWN });
|
|
162
|
+
|
|
163
|
+
expect(secondItem.element).not.toHaveFocus();
|
|
164
|
+
expect(thirdItem.element).toHaveFocus();
|
|
165
|
+
|
|
166
|
+
await thirdItem.trigger('keydown', { code: ARROW_UP });
|
|
167
|
+
expect(firstItem.element).toHaveFocus();
|
|
168
|
+
});
|
|
169
|
+
});
|
|
150
170
|
});
|
|
151
171
|
|
|
152
172
|
describe('slot content', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!-- eslint-disable vue/multi-word-component-names -->
|
|
2
2
|
<script>
|
|
3
3
|
import { clamp, uniqueId } from 'lodash';
|
|
4
|
-
import { stopEvent } from '../../../../utils/utils';
|
|
4
|
+
import { stopEvent, filterVisible } from '../../../../utils/utils';
|
|
5
5
|
import {
|
|
6
6
|
GL_DROPDOWN_SHOWN,
|
|
7
7
|
GL_DROPDOWN_HIDDEN,
|
|
@@ -116,7 +116,7 @@ export default {
|
|
|
116
116
|
toggleId: {
|
|
117
117
|
type: String,
|
|
118
118
|
required: false,
|
|
119
|
-
default:
|
|
119
|
+
default: uniqueId('dropdown-toggle-btn-'),
|
|
120
120
|
},
|
|
121
121
|
/**
|
|
122
122
|
* Additional CSS classes to customize toggle appearance
|
|
@@ -246,7 +246,7 @@ export default {
|
|
|
246
246
|
},
|
|
247
247
|
getFocusableListItemElements() {
|
|
248
248
|
const items = this.$refs.content?.querySelectorAll(`.${ITEM_CLASS}`);
|
|
249
|
-
return Array.from(items || []);
|
|
249
|
+
return filterVisible(Array.from(items || []));
|
|
250
250
|
},
|
|
251
251
|
focusNextItem(event, elements, offset) {
|
|
252
252
|
const { target } = event;
|
|
@@ -56,6 +56,26 @@ describe('GlDisclosureDropdownItem', () => {
|
|
|
56
56
|
expect(findLink().attributes('href')).toBe(mockItems[0].href);
|
|
57
57
|
expect(findLink().attributes()).toMatchObject(mockItems[0].extraAttrs);
|
|
58
58
|
});
|
|
59
|
+
|
|
60
|
+
it('should apply the default classes to the item wrapper', () => {
|
|
61
|
+
expect(findItem().classes()).toEqual(['gl-new-dropdown-item']);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('when item has wrapperClass', () => {
|
|
65
|
+
const TEST_CLASS = 'just-a-test-class';
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
buildWrapper({
|
|
68
|
+
item: {
|
|
69
|
+
...mockItems[0],
|
|
70
|
+
wrapperClass: TEST_CLASS,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should add the extra class to the item wrapper', () => {
|
|
76
|
+
expect(findItem().classes()).toContain(TEST_CLASS);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
59
79
|
});
|
|
60
80
|
|
|
61
81
|
describe('when item has an `action`', () => {
|
|
@@ -102,5 +122,35 @@ describe('GlDisclosureDropdownItem', () => {
|
|
|
102
122
|
trigger();
|
|
103
123
|
expect(wrapper.emitted('action')).toEqual([[item]]);
|
|
104
124
|
});
|
|
125
|
+
|
|
126
|
+
it('should apply the default classes to the item wrapper', () => {
|
|
127
|
+
expect(findItem().classes()).toEqual(['gl-new-dropdown-item']);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('when item has wrapperClass', () => {
|
|
131
|
+
const TEST_CLASS = 'just-a-test-class';
|
|
132
|
+
beforeEach(() => {
|
|
133
|
+
buildWrapper({
|
|
134
|
+
item: {
|
|
135
|
+
...mockItems[1],
|
|
136
|
+
wrapperClass: TEST_CLASS,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('should add the extra class to the item wrapper', () => {
|
|
142
|
+
expect(findItem().classes()).toContain(TEST_CLASS);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe('when item is null', () => {
|
|
148
|
+
beforeEach(() => {
|
|
149
|
+
buildWrapper({ item: null });
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should not render anything', () => {
|
|
153
|
+
expect(wrapper.text()).toBe('');
|
|
154
|
+
});
|
|
105
155
|
});
|
|
106
156
|
});
|
|
@@ -25,6 +25,8 @@ export default {
|
|
|
25
25
|
itemComponent() {
|
|
26
26
|
const { item } = this;
|
|
27
27
|
|
|
28
|
+
if (!item) return null;
|
|
29
|
+
|
|
28
30
|
if (this.isLink)
|
|
29
31
|
return {
|
|
30
32
|
is: 'a',
|
|
@@ -32,6 +34,7 @@ export default {
|
|
|
32
34
|
href: item.href,
|
|
33
35
|
...item.extraAttrs,
|
|
34
36
|
},
|
|
37
|
+
wrapperClass: item.wrapperClass,
|
|
35
38
|
listeners: {},
|
|
36
39
|
};
|
|
37
40
|
|
|
@@ -44,6 +47,7 @@ export default {
|
|
|
44
47
|
listeners: {
|
|
45
48
|
click: () => item.action?.call(undefined, item),
|
|
46
49
|
},
|
|
50
|
+
wrapperClass: item.wrapperClass,
|
|
47
51
|
};
|
|
48
52
|
},
|
|
49
53
|
},
|
|
@@ -72,8 +76,7 @@ export default {
|
|
|
72
76
|
<template>
|
|
73
77
|
<li
|
|
74
78
|
tabindex="0"
|
|
75
|
-
:class="$options.ITEM_CLASS"
|
|
76
|
-
class="gl-new-dropdown-item"
|
|
79
|
+
:class="[$options.ITEM_CLASS, itemComponent && itemComponent.wrapperClass]"
|
|
77
80
|
data-testid="disclosure-dropdown-item"
|
|
78
81
|
@click="action"
|
|
79
82
|
@keydown="onKeydown"
|
|
@@ -84,7 +87,7 @@ export default {
|
|
|
84
87
|
</div>
|
|
85
88
|
</div>
|
|
86
89
|
|
|
87
|
-
<template v-else>
|
|
90
|
+
<template v-else-if="itemComponent && item">
|
|
88
91
|
<component
|
|
89
92
|
:is="itemComponent.is"
|
|
90
93
|
v-bind="itemComponent.attrs"
|
|
@@ -49,6 +49,14 @@ export const mockItemsCustomItem = [
|
|
|
49
49
|
rel: 'nofollow',
|
|
50
50
|
},
|
|
51
51
|
},
|
|
52
|
+
{
|
|
53
|
+
text: 'I am only visible on mobile!',
|
|
54
|
+
action: () => {
|
|
55
|
+
// eslint-disable-next-line no-console
|
|
56
|
+
console.log('clicked!');
|
|
57
|
+
},
|
|
58
|
+
wrapperClass: 'gl-sm-display-none!',
|
|
59
|
+
},
|
|
52
60
|
];
|
|
53
61
|
|
|
54
62
|
export const mockGroupsCustomItem = [
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
ARROW_UP,
|
|
10
10
|
HOME,
|
|
11
11
|
END,
|
|
12
|
+
ENTER,
|
|
12
13
|
} from '../constants';
|
|
13
14
|
import GlIntersectionObserver from '../../../utilities/intersection_observer/intersection_observer.vue';
|
|
14
15
|
import GlListbox, { ITEM_SELECTOR } from './listbox.vue';
|
|
@@ -273,6 +274,27 @@ describe('GlListbox', () => {
|
|
|
273
274
|
firstItem.trigger('keydown', { code: ARROW_UP });
|
|
274
275
|
expect(searchboxInput.element).toHaveFocus();
|
|
275
276
|
});
|
|
277
|
+
|
|
278
|
+
describe('pressing Enter on the input', () => {
|
|
279
|
+
const keydownSpy = jest.fn();
|
|
280
|
+
|
|
281
|
+
beforeEach(() => {
|
|
282
|
+
keydownSpy.mockClear();
|
|
283
|
+
wrapper.element.addEventListener('keydown', keydownSpy);
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
afterEach(() => {
|
|
287
|
+
wrapper.element.removeEventListener('keydown', keydownSpy);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('does not submit any ancestor form', async () => {
|
|
291
|
+
searchboxInput.trigger('keydown', { key: ENTER });
|
|
292
|
+
|
|
293
|
+
const [event] = keydownSpy.mock.calls[0];
|
|
294
|
+
expect(event.key).toBe(ENTER);
|
|
295
|
+
expect(event.defaultPrevented).toBe(true);
|
|
296
|
+
});
|
|
297
|
+
});
|
|
276
298
|
});
|
|
277
299
|
});
|
|
278
300
|
|
package/src/scss/fonts.scss
CHANGED
|
@@ -14,7 +14,7 @@ Usage:
|
|
|
14
14
|
font-display: block;
|
|
15
15
|
font-style: normal;
|
|
16
16
|
font-named-instance: 'Regular'; /* stylelint-disable property-no-unknown */
|
|
17
|
-
src: url('/fonts/GitLabSans.woff2') format('woff2');
|
|
17
|
+
src: url('../../static/fonts/GitLabSans.woff2') format('woff2');
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/* -------------------------------------------------------
|
|
@@ -31,5 +31,5 @@ Usage:
|
|
|
31
31
|
*/
|
|
32
32
|
font-display: block;
|
|
33
33
|
font-style: normal;
|
|
34
|
-
src: url('/fonts/JetBrainsMono.woff2') format('woff2');
|
|
34
|
+
src: url('../../static/fonts/JetBrainsMono.woff2') format('woff2');
|
|
35
35
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isVisible } from 'bootstrap-vue/src/utils/dom';
|
|
1
2
|
import { COMMA, labelColorOptions, focusableTags } from './constants';
|
|
2
3
|
|
|
3
4
|
export function debounceByAnimationFrame(fn) {
|
|
@@ -140,3 +141,10 @@ export function stopEvent(
|
|
|
140
141
|
event.stopImmediatePropagation();
|
|
141
142
|
}
|
|
142
143
|
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Return an Array of visible items
|
|
147
|
+
*/
|
|
148
|
+
export function filterVisible(els) {
|
|
149
|
+
return (els || []).filter(isVisible);
|
|
150
|
+
}
|