@gitlab/ui 54.3.0 → 54.4.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 +7 -0
- 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/utils/utils.js +9 -1
- package/package.json +1 -1
- 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/utils/utils.js +8 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [54.4.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v54.3.0...v54.4.0) (2023-02-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **GlDisclosureDropdown:** Add support for item wrapper class ([8b575af](https://gitlab.com/gitlab-org/gitlab-ui/commit/8b575af03dcdeb9206ef3caf65f2519b9628b1ae))
|
|
7
|
+
|
|
1
8
|
# [54.3.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v54.2.3...v54.3.0) (2023-02-02)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -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',
|
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
|
@@ -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 = [
|
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
|
+
}
|