@gitlab/ui 54.2.3 → 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 +14 -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/utility_classes.css +1 -1
- package/dist/utility_classes.css.map +1 -1
- package/dist/utils/utils.js +9 -1
- package/package.json +2 -2
- 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/scss/utilities.scss +8 -0
- package/src/scss/utility-mixins/sizing.scss +4 -0
- package/src/utils/utils.js +8 -0
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.0",
|
|
4
4
|
"description": "GitLab UI Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"@gitlab/eslint-plugin": "18.1.0",
|
|
88
88
|
"@gitlab/fonts": "^1.2.0",
|
|
89
89
|
"@gitlab/stylelint-config": "4.1.0",
|
|
90
|
-
"@gitlab/svgs": "3.
|
|
90
|
+
"@gitlab/svgs": "3.18.0",
|
|
91
91
|
"@rollup/plugin-commonjs": "^11.1.0",
|
|
92
92
|
"@rollup/plugin-node-resolve": "^7.1.3",
|
|
93
93
|
"@rollup/plugin-replace": "^2.3.2",
|
|
@@ -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/scss/utilities.scss
CHANGED
|
@@ -4963,6 +4963,14 @@
|
|
|
4963
4963
|
min-height: 0 !important;
|
|
4964
4964
|
}
|
|
4965
4965
|
|
|
4966
|
+
.gl-min-h-5 {
|
|
4967
|
+
min-height: $gl-spacing-scale-5;
|
|
4968
|
+
}
|
|
4969
|
+
|
|
4970
|
+
.gl-min-h-5\! {
|
|
4971
|
+
min-height: $gl-spacing-scale-5 !important;
|
|
4972
|
+
}
|
|
4973
|
+
|
|
4966
4974
|
.gl-min-h-6 {
|
|
4967
4975
|
min-height: $gl-spacing-scale-6;
|
|
4968
4976
|
}
|
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
|
+
}
|