Skip to content

Commit 9cc21fe

Browse files
committed
progress
1 parent ba13360 commit 9cc21fe

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

web_src/js/behaviours/overflow-menu.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,41 @@
11
import {throttle} from 'throttle-debounce';
2-
import {isHorizontallyOverflown, createElementFromHTML} from '../utils/dom.js';
32
import {svg} from '../svg.js';
4-
import $ from 'jquery';
3+
import {createTippy} from '../modules/tippy.js';
54

65
const update = throttle(100, (menu) => {
7-
const isOverflown = isHorizontallyOverflown(menu);
8-
if (isOverflown) {
9-
const overflownItems = [];
10-
const {right: menuRight} = menu.getBoundingClientRect();
11-
for (const item of menu.querySelectorAll('.overflow-menu-items .item')) {
12-
const {right: itemRight} = item.getBoundingClientRect();
13-
if (itemRight >= menuRight) {
14-
overflownItems.push(item.cloneNode(true));
15-
item.remove();
16-
}
6+
const menuItems = menu.querySelectorAll('.overflow-menu-items .item');
7+
const buttonItems = [];
8+
9+
const {right: menuRight} = menu.getBoundingClientRect();
10+
for (const item of menuItems) {
11+
const {right: itemRight} = item.getBoundingClientRect();
12+
if (itemRight >= menuRight) {
13+
buttonItems.push(item.cloneNode(true));
14+
item.remove();
1715
}
18-
if (overflownItems.length) {
19-
menu.querySelector('.overflow-menu')?.remove();
20-
menu.append(createElementFromHTML(`
21-
<div class="ui dropdown overflow-menu gt-px-2">
22-
<div class="text">${svg('octicon-kebab-horizontal')}</div>
23-
<div class="menu">${overflownItems.map((item) => item.outerHTML).join('')}</div>
24-
</div>
25-
`));
26-
$(menu).dropdown();
16+
}
17+
18+
if (buttonItems.length && !menu.querySelector('.overflow-menu-button')) {
19+
const btn = document.createElement('button');
20+
btn.classList.add('overflow-menu-button', 'btn', 'tw-px-4');
21+
btn.innerHTML = svg('octicon-kebab-horizontal');
22+
23+
const itemsMenu = document.createElement('div');
24+
itemsMenu.classList.add('overflow-menu-tippy', 'ui', 'vertical', 'menu');
25+
for (const item of buttonItems) {
26+
itemsMenu.append(item);
2727
}
28+
29+
createTippy(btn, {
30+
trigger: 'click',
31+
hideOnClick: true,
32+
interactive: true,
33+
placement: 'bottom-end',
34+
role: 'menu',
35+
content: itemsMenu,
36+
});
37+
38+
menu.append(btn);
2839
}
2940
});
3041

web_src/js/utils/dom.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,3 @@ export function isElemVisible(element) {
243243

244244
return Boolean(element.offsetWidth || element.offsetHeight || element.getClientRects().length);
245245
}
246-
247-
export function isHorizontallyOverflown(el) {
248-
return (el.scrollWidth ?? 0) - (el.clientWidth ?? 0) > 0;
249-
}
250-
251-
export function createElementFromHTML(str) {
252-
const div = document.createElement('div');
253-
div.innerHTML = str.trim();
254-
return div.firstChild;
255-
}

0 commit comments

Comments
 (0)