Skip to content

Commit 059b271

Browse files
authored
Right align the "Settings" menu item in overflow-menu (go-gitea#30764)
I guess there could be enough people liking to make the Settings menu item right aligned. As a site admin, I found it's easier to find the right-aligned Settings menu item. Tested with various sizes: ![image](https://github.com/go-gitea/gitea/assets/2114189/92836527-2cb2-4531-9296-233c5bd698f4) ![image](https://github.com/go-gitea/gitea/assets/2114189/3a0729fc-5e33-44b5-9fb4-3a4e787405b5) ![image](https://github.com/go-gitea/gitea/assets/2114189/9845ab6b-88e3-4e5a-8d6d-2b8af259d593)
1 parent 7ad5031 commit 059b271

File tree

5 files changed

+39
-38
lines changed

5 files changed

+39
-38
lines changed

templates/org/menu.tmpl

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@
4040
</a>
4141
{{end}}
4242
{{if .IsOrganizationOwner}}
43+
<span class="item-flex-space"></span>
4344
<a class="{{if .PageIsOrgSettings}}active {{end}}item" href="{{.OrgLink}}/settings">
44-
{{svg "octicon-tools"}} {{ctx.Locale.Tr "repo.settings"}}
45+
{{svg "octicon-tools"}} {{ctx.Locale.Tr "repo.settings"}}
4546
</a>
4647
{{end}}
4748
</div>

templates/repo/header.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
{{template "custom/extra_tabs" .}}
217217

218218
{{if .Permission.IsAdmin}}
219+
<span class="item-flex-space"></span>
219220
<a class="{{if .PageIsRepoSettings}}active {{end}} item" href="{{.RepoLink}}/settings">
220221
{{svg "octicon-tools"}} {{ctx.Locale.Tr "repo.settings"}}
221222
</a>

web_src/css/base.css

+17
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,23 @@ overflow-menu .overflow-menu-items .item {
938938
margin-bottom: 0 !important; /* reset fomantic's margin, because the active menu has special bottom border */
939939
}
940940

941+
overflow-menu .overflow-menu-items .item-flex-space {
942+
flex: 1;
943+
}
944+
945+
overflow-menu .overflow-menu-button {
946+
background: transparent;
947+
border: none;
948+
color: inherit;
949+
text-align: center;
950+
width: 32px;
951+
padding: 0;
952+
}
953+
954+
overflow-menu .overflow-menu-button:hover {
955+
color: var(--color-text-dark);
956+
}
957+
941958
overflow-menu .ui.label {
942959
margin-left: 7px !important; /* save some space */
943960
}

web_src/css/modules/container.css

-32
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,6 @@
66
max-width: 100%;
77
}
88

9-
@media (max-width: 767.98px) {
10-
.ui.ui.ui.container:not(.fluid) {
11-
width: auto;
12-
margin-left: 1em;
13-
margin-right: 1em;
14-
}
15-
}
16-
17-
@media (min-width: 768px) and (max-width: 991.98px) {
18-
.ui.ui.ui.container:not(.fluid) {
19-
width: 723px;
20-
margin-left: auto;
21-
margin-right: auto;
22-
}
23-
}
24-
25-
@media (min-width: 992px) and (max-width: 1199.98px) {
26-
.ui.ui.ui.container:not(.fluid) {
27-
width: 933px;
28-
margin-left: auto;
29-
margin-right: auto;
30-
}
31-
}
32-
33-
@media (min-width: 1200px) {
34-
.ui.ui.ui.container:not(.fluid) {
35-
width: 1127px;
36-
margin-left: auto;
37-
margin-right: auto;
38-
}
39-
}
40-
419
.ui.fluid.container {
4210
width: 100%;
4311
}

web_src/js/webcomponents/overflow-menu.js

+19-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
88
if (!this.tippyContent) {
99
const div = document.createElement('div');
1010
div.classList.add('tippy-target');
11-
div.tabIndex = '-1'; // for initial focus, programmatic focus only
11+
div.tabIndex = -1; // for initial focus, programmatic focus only
1212
div.addEventListener('keydown', (e) => {
1313
if (e.key === 'Tab') {
1414
const items = this.tippyContent.querySelectorAll('[role="menuitem"]');
@@ -60,21 +60,35 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
6060
this.tippyContent = div;
6161
}
6262

63+
const itemFlexSpace = this.menuItemsEl.querySelector('.item-flex-space');
64+
6365
// move items in tippy back into the menu items for subsequent measurement
6466
for (const item of this.tippyItems || []) {
65-
this.menuItemsEl.append(item);
67+
if (!itemFlexSpace || item.getAttribute('data-after-flex-space')) {
68+
this.menuItemsEl.append(item);
69+
} else {
70+
itemFlexSpace.insertAdjacentElement('beforebegin', item);
71+
}
6672
}
6773

6874
// measure which items are partially outside the element and move them into the button menu
75+
itemFlexSpace?.style.setProperty('display', 'none', 'important');
6976
this.tippyItems = [];
7077
const menuRight = this.offsetLeft + this.offsetWidth;
71-
const menuItems = this.menuItemsEl.querySelectorAll('.item');
78+
const menuItems = this.menuItemsEl.querySelectorAll('.item, .item-flex-space');
79+
let afterFlexSpace = false;
7280
for (const item of menuItems) {
81+
if (item.classList.contains('item-flex-space')) {
82+
afterFlexSpace = true;
83+
continue;
84+
}
85+
if (afterFlexSpace) item.setAttribute('data-after-flex-space', 'true');
7386
const itemRight = item.offsetLeft + item.offsetWidth;
74-
if (menuRight - itemRight < 38) { // roughly the width of .overflow-menu-button
87+
if (menuRight - itemRight < 38) { // roughly the width of .overflow-menu-button with some extra space
7588
this.tippyItems.push(item);
7689
}
7790
}
91+
itemFlexSpace?.style.removeProperty('display');
7892

7993
// if there are no overflown items, remove any previously created button
8094
if (!this.tippyItems?.length) {
@@ -105,7 +119,7 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
105119

106120
// create button initially
107121
const btn = document.createElement('button');
108-
btn.classList.add('overflow-menu-button', 'btn', 'tw-px-2', 'hover:tw-text-text-dark');
122+
btn.classList.add('overflow-menu-button');
109123
btn.setAttribute('aria-label', window.config.i18n.more_items);
110124
btn.innerHTML = octiconKebabHorizontal;
111125
this.append(btn);

0 commit comments

Comments
 (0)