@gitlab/ui 78.19.0 → 79.0.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 +22 -0
- package/dist/components/base/new_dropdowns/base_dropdown/base_dropdown.js +4 -3
- package/dist/components/base/new_dropdowns/constants.js +2 -1
- package/dist/tokens/css/tokens.css +1 -1
- package/dist/tokens/css/tokens.dark.css +1 -1
- package/dist/tokens/js/tokens.dark.js +1 -1
- package/dist/tokens/js/tokens.js +1 -1
- package/dist/tokens/scss/_tokens.dark.scss +1 -1
- package/dist/tokens/scss/_tokens.scss +1 -1
- package/dist/utils/story_decorators/container.js +10 -7
- package/package.json +1 -1
- package/src/components/base/new_dropdowns/base_dropdown/base_dropdown.spec.js +52 -12
- package/src/components/base/new_dropdowns/base_dropdown/base_dropdown.vue +4 -1
- package/src/components/base/new_dropdowns/constants.js +1 -0
- package/src/components/base/new_dropdowns/disclosure/disclosure_dropdown.stories.js +28 -0
- package/src/utils/story_decorators/container.js +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
# [79.0.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v78.19.0...v79.0.0) (2024-04-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **BaseDropdown:** Use a "main" element boundary when available ([ee0cd82](https://gitlab.com/gitlab-org/gitlab-ui/commit/ee0cd82b8b2ae6986052877250884ce9cd43df21))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### BREAKING CHANGES
|
|
10
|
+
|
|
11
|
+
* **BaseDropdown:** This change slightly alters the default positioning
|
|
12
|
+
of GlDisclosureDropdown and GlListbox.
|
|
13
|
+
|
|
14
|
+
If the dropdown is placed inside a <main> element: The disclosure
|
|
15
|
+
will use main as a boundary to not overflow it. This change aims
|
|
16
|
+
to smartly reduce the need to use custom "placement" ('right'
|
|
17
|
+
and 'bottom-end') options, especially when the dropdown is placed
|
|
18
|
+
on the right side, such as in contextual menus.
|
|
19
|
+
|
|
20
|
+
If the dropdown is not placed in a <main> element, behavior does
|
|
21
|
+
change.
|
|
22
|
+
|
|
1
23
|
# [78.19.0](https://gitlab.com/gitlab-org/gitlab-ui/compare/v78.18.0...v78.19.0) (2024-04-22)
|
|
2
24
|
|
|
3
25
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import uniqueId from 'lodash/uniqueId';
|
|
2
|
-
import { offset, autoPlacement, size, autoUpdate, computePosition } from '@floating-ui/dom';
|
|
2
|
+
import { offset, autoPlacement, shift, size, autoUpdate, computePosition } from '@floating-ui/dom';
|
|
3
3
|
import { buttonCategoryOptions, dropdownVariantOptions, buttonSizeOptions, dropdownPlacements, dropdownAllowedAutoPlacements } from '../../../../utils/constants';
|
|
4
|
-
import { POSITION_ABSOLUTE, POSITION_FIXED, GL_DROPDOWN_CONTENTS_CLASS, GL_DROPDOWN_BEFORE_CLOSE, GL_DROPDOWN_SHOWN, GL_DROPDOWN_HIDDEN, ENTER, SPACE, ARROW_DOWN, GL_DROPDOWN_FOCUS_CONTENT } from '../constants';
|
|
4
|
+
import { POSITION_ABSOLUTE, POSITION_FIXED, GL_DROPDOWN_BOUNDARY_SELECTOR, GL_DROPDOWN_CONTENTS_CLASS, GL_DROPDOWN_BEFORE_CLOSE, GL_DROPDOWN_SHOWN, GL_DROPDOWN_HIDDEN, ENTER, SPACE, ARROW_DOWN, GL_DROPDOWN_FOCUS_CONTENT } from '../constants';
|
|
5
5
|
import { logWarning, isElementFocusable, isElementTabbable } from '../../../../utils/utils';
|
|
6
6
|
import GlButton from '../../button/button';
|
|
7
7
|
import GlIcon from '../../icon/icon';
|
|
@@ -252,8 +252,9 @@ var script = {
|
|
|
252
252
|
strategy: this.positioningStrategy,
|
|
253
253
|
middleware: [offset(this.offset), autoPlacement({
|
|
254
254
|
alignment,
|
|
255
|
+
boundary: this.$el.closest(GL_DROPDOWN_BOUNDARY_SELECTOR) || 'clippingAncestors',
|
|
255
256
|
allowedPlacements: dropdownAllowedAutoPlacements[this.placement]
|
|
256
|
-
}), size({
|
|
257
|
+
}), shift(), size({
|
|
257
258
|
apply: _ref => {
|
|
258
259
|
var _this$nonScrollableCo;
|
|
259
260
|
let {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// base dropdown events
|
|
2
|
+
const GL_DROPDOWN_BOUNDARY_SELECTOR = 'main';
|
|
2
3
|
const GL_DROPDOWN_SHOWN = 'shown';
|
|
3
4
|
const GL_DROPDOWN_HIDDEN = 'hidden';
|
|
4
5
|
const GL_DROPDOWN_BEFORE_CLOSE = 'beforeClose';
|
|
@@ -18,4 +19,4 @@ const POSITION_ABSOLUTE = 'absolute';
|
|
|
18
19
|
const POSITION_FIXED = 'fixed';
|
|
19
20
|
const GL_DROPDOWN_CONTENTS_CLASS = 'gl-new-dropdown-contents';
|
|
20
21
|
|
|
21
|
-
export { ARROW_DOWN, ARROW_UP, END, ENTER, GL_DROPDOWN_BEFORE_CLOSE, GL_DROPDOWN_CONTENTS_CLASS, GL_DROPDOWN_FOCUS_CONTENT, GL_DROPDOWN_HIDDEN, GL_DROPDOWN_SHOWN, HOME, POSITION_ABSOLUTE, POSITION_FIXED, SPACE };
|
|
22
|
+
export { ARROW_DOWN, ARROW_UP, END, ENTER, GL_DROPDOWN_BEFORE_CLOSE, GL_DROPDOWN_BOUNDARY_SELECTOR, GL_DROPDOWN_CONTENTS_CLASS, GL_DROPDOWN_FOCUS_CONTENT, GL_DROPDOWN_HIDDEN, GL_DROPDOWN_SHOWN, HOME, POSITION_ABSOLUTE, POSITION_FIXED, SPACE };
|
package/dist/tokens/js/tokens.js
CHANGED
|
@@ -5,12 +5,15 @@
|
|
|
5
5
|
* @param {object} style The style attribute to apply to the container.
|
|
6
6
|
* @return {function} The story decorator.
|
|
7
7
|
*/
|
|
8
|
-
const makeContainer = style
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
});
|
|
8
|
+
const makeContainer = function (style) {
|
|
9
|
+
let tag = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'div';
|
|
10
|
+
return Story => ({
|
|
11
|
+
render(h) {
|
|
12
|
+
return h(tag, {
|
|
13
|
+
style
|
|
14
|
+
}, [h(Story())]);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
15
18
|
|
|
16
19
|
export { makeContainer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { mount } from '@vue/test-utils';
|
|
2
2
|
import { nextTick } from 'vue';
|
|
3
|
-
import { computePosition, autoUpdate, offset, autoPlacement } from '@floating-ui/dom';
|
|
3
|
+
import { computePosition, autoUpdate, offset, autoPlacement, shift } from '@floating-ui/dom';
|
|
4
4
|
import {
|
|
5
5
|
ARROW_DOWN,
|
|
6
6
|
GL_DROPDOWN_FOCUS_CONTENT,
|
|
@@ -15,8 +15,9 @@ import GlBaseDropdown from './base_dropdown.vue';
|
|
|
15
15
|
|
|
16
16
|
jest.mock('@floating-ui/dom');
|
|
17
17
|
const mockStopAutoUpdate = jest.fn();
|
|
18
|
-
offset.mockImplementation((
|
|
19
|
-
autoPlacement.mockImplementation((
|
|
18
|
+
offset.mockImplementation((offsetOpts = {}) => ({ offsetOpts }));
|
|
19
|
+
autoPlacement.mockImplementation((autoPlacementOpts = {}) => ({ autoPlacementOpts }));
|
|
20
|
+
shift.mockImplementation((shiftOpts = {}) => ({ shiftOpts }));
|
|
20
21
|
|
|
21
22
|
const DEFAULT_BTN_TOGGLE_CLASSES = [
|
|
22
23
|
'btn',
|
|
@@ -29,7 +30,7 @@ const DEFAULT_BTN_TOGGLE_CLASSES = [
|
|
|
29
30
|
describe('base dropdown', () => {
|
|
30
31
|
let wrapper;
|
|
31
32
|
|
|
32
|
-
const buildWrapper = (propsData, slots = {},
|
|
33
|
+
const buildWrapper = (propsData, { slots = {}, ...options } = {}) => {
|
|
33
34
|
wrapper = mount(GlBaseDropdown, {
|
|
34
35
|
propsData: {
|
|
35
36
|
toggleId: 'dropdown-toggle-btn-1',
|
|
@@ -40,7 +41,7 @@ describe('base dropdown', () => {
|
|
|
40
41
|
...slots,
|
|
41
42
|
},
|
|
42
43
|
attachTo: document.body,
|
|
43
|
-
|
|
44
|
+
...options,
|
|
44
45
|
});
|
|
45
46
|
};
|
|
46
47
|
|
|
@@ -99,6 +100,35 @@ describe('base dropdown', () => {
|
|
|
99
100
|
autoUpdate.mockImplementation(jest.requireActual('@floating-ui/dom').autoUpdate);
|
|
100
101
|
});
|
|
101
102
|
|
|
103
|
+
it('initializes Floating UI with a default boundary', async () => {
|
|
104
|
+
document.body.innerHTML = '<main><div></div></main>';
|
|
105
|
+
|
|
106
|
+
buildWrapper(undefined, {
|
|
107
|
+
attachTo: document.querySelector('main div'),
|
|
108
|
+
});
|
|
109
|
+
await findDefaultDropdownToggle().trigger('click');
|
|
110
|
+
|
|
111
|
+
expect(computePosition).toHaveBeenCalledWith(
|
|
112
|
+
findDefaultDropdownToggle().element,
|
|
113
|
+
findDropdownMenu().element,
|
|
114
|
+
{
|
|
115
|
+
placement: 'bottom-start',
|
|
116
|
+
strategy: 'absolute',
|
|
117
|
+
middleware: [
|
|
118
|
+
offset({ mainAxis: DEFAULT_OFFSET }),
|
|
119
|
+
autoPlacement({
|
|
120
|
+
alignment: 'start',
|
|
121
|
+
boundary: document.querySelector('main'),
|
|
122
|
+
allowedPlacements: ['bottom-start', 'top-start', 'bottom-end', 'top-end'],
|
|
123
|
+
}),
|
|
124
|
+
shift(),
|
|
125
|
+
],
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
document.body.innerHTML = '';
|
|
130
|
+
});
|
|
131
|
+
|
|
102
132
|
it('initializes Floating UI with reference and floating elements and config for left-aligned menu', async () => {
|
|
103
133
|
buildWrapper();
|
|
104
134
|
await findDefaultDropdownToggle().trigger('click');
|
|
@@ -113,8 +143,10 @@ describe('base dropdown', () => {
|
|
|
113
143
|
offset({ mainAxis: DEFAULT_OFFSET }),
|
|
114
144
|
autoPlacement({
|
|
115
145
|
alignment: 'start',
|
|
146
|
+
boundary: 'clippingAncestors',
|
|
116
147
|
allowedPlacements: ['bottom-start', 'top-start', 'bottom-end', 'top-end'],
|
|
117
148
|
}),
|
|
149
|
+
shift(),
|
|
118
150
|
],
|
|
119
151
|
}
|
|
120
152
|
);
|
|
@@ -134,8 +166,10 @@ describe('base dropdown', () => {
|
|
|
134
166
|
offset({ mainAxis: DEFAULT_OFFSET }),
|
|
135
167
|
autoPlacement({
|
|
136
168
|
alignment: undefined,
|
|
169
|
+
boundary: 'clippingAncestors',
|
|
137
170
|
allowedPlacements: ['bottom', 'top'],
|
|
138
171
|
}),
|
|
172
|
+
shift(),
|
|
139
173
|
],
|
|
140
174
|
}
|
|
141
175
|
);
|
|
@@ -155,8 +189,10 @@ describe('base dropdown', () => {
|
|
|
155
189
|
offset({ mainAxis: DEFAULT_OFFSET }),
|
|
156
190
|
autoPlacement({
|
|
157
191
|
alignment: 'end',
|
|
192
|
+
boundary: 'clippingAncestors',
|
|
158
193
|
allowedPlacements: ['bottom-start', 'top-start', 'bottom-end', 'top-end'],
|
|
159
194
|
}),
|
|
195
|
+
shift(),
|
|
160
196
|
],
|
|
161
197
|
}
|
|
162
198
|
);
|
|
@@ -176,8 +212,10 @@ describe('base dropdown', () => {
|
|
|
176
212
|
offset({ mainAxis: DEFAULT_OFFSET }),
|
|
177
213
|
autoPlacement({
|
|
178
214
|
alignment: 'start',
|
|
215
|
+
boundary: 'clippingAncestors',
|
|
179
216
|
allowedPlacements: ['right-start', 'right-end', 'left-start', 'left-end'],
|
|
180
217
|
}),
|
|
218
|
+
shift(),
|
|
181
219
|
],
|
|
182
220
|
}
|
|
183
221
|
);
|
|
@@ -197,7 +235,7 @@ describe('base dropdown', () => {
|
|
|
197
235
|
{
|
|
198
236
|
placement: 'bottom-end',
|
|
199
237
|
strategy: 'absolute',
|
|
200
|
-
middleware: [offset(customOffset), autoPlacement(expect.any(Object))],
|
|
238
|
+
middleware: [offset(customOffset), autoPlacement(expect.any(Object)), shift()],
|
|
201
239
|
}
|
|
202
240
|
);
|
|
203
241
|
});
|
|
@@ -245,7 +283,7 @@ describe('base dropdown', () => {
|
|
|
245
283
|
const slots = { default: defaultContent };
|
|
246
284
|
|
|
247
285
|
it('renders the content', () => {
|
|
248
|
-
buildWrapper({}, slots);
|
|
286
|
+
buildWrapper({}, { slots });
|
|
249
287
|
expect(wrapper.find('.gl-new-dropdown-inner').html()).toContain(defaultContent);
|
|
250
288
|
});
|
|
251
289
|
});
|
|
@@ -409,10 +447,12 @@ describe('base dropdown', () => {
|
|
|
409
447
|
|
|
410
448
|
beforeEach(() => {
|
|
411
449
|
event = undefined;
|
|
412
|
-
buildWrapper(undefined,
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
450
|
+
buildWrapper(undefined, {
|
|
451
|
+
listeners: {
|
|
452
|
+
[GL_DROPDOWN_BEFORE_CLOSE]({ originalEvent, preventDefault }) {
|
|
453
|
+
event = originalEvent;
|
|
454
|
+
preventDefault();
|
|
455
|
+
},
|
|
416
456
|
},
|
|
417
457
|
});
|
|
418
458
|
});
|
|
@@ -467,7 +507,7 @@ describe('base dropdown', () => {
|
|
|
467
507
|
|
|
468
508
|
beforeEach(() => {
|
|
469
509
|
const slots = { toggle: toggleContent };
|
|
470
|
-
buildWrapper({}, slots);
|
|
510
|
+
buildWrapper({}, { slots });
|
|
471
511
|
});
|
|
472
512
|
|
|
473
513
|
it('does not render default toggle button', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script>
|
|
2
2
|
import uniqueId from 'lodash/uniqueId';
|
|
3
|
-
import { computePosition, autoUpdate, offset, size, autoPlacement } from '@floating-ui/dom';
|
|
3
|
+
import { computePosition, autoUpdate, offset, size, autoPlacement, shift } from '@floating-ui/dom';
|
|
4
4
|
import {
|
|
5
5
|
buttonCategoryOptions,
|
|
6
6
|
buttonSizeOptions,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
dropdownVariantOptions,
|
|
10
10
|
} from '../../../../utils/constants';
|
|
11
11
|
import {
|
|
12
|
+
GL_DROPDOWN_BOUNDARY_SELECTOR,
|
|
12
13
|
GL_DROPDOWN_SHOWN,
|
|
13
14
|
GL_DROPDOWN_HIDDEN,
|
|
14
15
|
GL_DROPDOWN_BEFORE_CLOSE,
|
|
@@ -272,8 +273,10 @@ export default {
|
|
|
272
273
|
offset(this.offset),
|
|
273
274
|
autoPlacement({
|
|
274
275
|
alignment,
|
|
276
|
+
boundary: this.$el.closest(GL_DROPDOWN_BOUNDARY_SELECTOR) || 'clippingAncestors',
|
|
275
277
|
allowedPlacements: dropdownAllowedAutoPlacements[this.placement],
|
|
276
278
|
}),
|
|
279
|
+
shift(),
|
|
277
280
|
size({
|
|
278
281
|
apply: ({ availableHeight, elements }) => {
|
|
279
282
|
const contentsEl = elements.floating.querySelector(`.${GL_DROPDOWN_CONTENTS_CLASS}`);
|
|
@@ -343,3 +343,31 @@ export default {
|
|
|
343
343
|
startOpened: true,
|
|
344
344
|
},
|
|
345
345
|
};
|
|
346
|
+
|
|
347
|
+
export const InMainWrapper = (args, { argTypes }) => ({
|
|
348
|
+
toggleId: TOGGLE_ID,
|
|
349
|
+
props: Object.keys(argTypes),
|
|
350
|
+
components: {
|
|
351
|
+
GlDisclosureDropdown,
|
|
352
|
+
GlTooltip,
|
|
353
|
+
},
|
|
354
|
+
template: `
|
|
355
|
+
<div>
|
|
356
|
+
${template()}
|
|
357
|
+
<gl-tooltip :target="$options.toggleId" placement="right">
|
|
358
|
+
Automatic placement to stay inside <main> boundary
|
|
359
|
+
</gl-tooltip>
|
|
360
|
+
</div>
|
|
361
|
+
`,
|
|
362
|
+
});
|
|
363
|
+
InMainWrapper.args = {
|
|
364
|
+
items: mockItems,
|
|
365
|
+
icon: 'ellipsis_v',
|
|
366
|
+
noCaret: true,
|
|
367
|
+
toggleText: 'Disclosure',
|
|
368
|
+
textSrOnly: true,
|
|
369
|
+
toggleId: TOGGLE_ID,
|
|
370
|
+
};
|
|
371
|
+
InMainWrapper.decorators = [
|
|
372
|
+
makeContainer({ backgroundColor: '#efefef', textAlign: 'right', height: '200px' }, 'main'),
|
|
373
|
+
];
|
|
@@ -5,8 +5,10 @@
|
|
|
5
5
|
* @param {object} style The style attribute to apply to the container.
|
|
6
6
|
* @return {function} The story decorator.
|
|
7
7
|
*/
|
|
8
|
-
export const makeContainer =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
8
|
+
export const makeContainer =
|
|
9
|
+
(style, tag = 'div') =>
|
|
10
|
+
(Story) => ({
|
|
11
|
+
render(h) {
|
|
12
|
+
return h(tag, { style }, [h(Story())]);
|
|
13
|
+
},
|
|
14
|
+
});
|