Skip to content

Commit 9a84017

Browse files
silverwindwxiaoguangGiteaBot
authored andcommitted
Fix navbar + menu flashing on page load (#31281)
Fixes go-gitea/gitea#31273 (comment). Same method as used in go-gitea/gitea#30215. All left-opening dropdowns need to use it method. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com> Co-authored-by: Giteabot <teabot@gitea.io>
1 parent 54c1a44 commit 9a84017

File tree

6 files changed

+46
-28
lines changed

6 files changed

+46
-28
lines changed

templates/base/head_navbar.tmpl

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{{end}}
55

66
<nav id="navbar" aria-label="{{ctx.Locale.Tr "aria.navbar"}}">
7-
<div class="navbar-left ui secondary menu">
7+
<div class="navbar-left">
88
<!-- the logo -->
99
<a class="item" id="navbar-logo" href="{{AppSubUrl}}/" aria-label="{{if .IsSigned}}{{ctx.Locale.Tr "dashboard"}}{{else}}{{ctx.Locale.Tr "home"}}{{end}}">
1010
<img width="30" height="30" src="{{AssetUrlPrefix}}/img/logo.svg" alt="{{ctx.Locale.Tr "logo"}}" aria-hidden="true">
@@ -62,7 +62,7 @@
6262
</div>
6363

6464
<!-- the full dropdown menus -->
65-
<div class="navbar-right ui secondary menu">
65+
<div class="navbar-right">
6666
{{if and .IsSigned .MustChangePassword}}
6767
<div class="ui dropdown jump item" data-tooltip-content="{{ctx.Locale.Tr "user_profile_and_more"}}">
6868
<span class="text tw-flex tw-items-center">
@@ -105,7 +105,7 @@
105105
<span class="not-mobile">{{svg "octicon-triangle-down"}}</span>
106106
<span class="only-mobile">{{ctx.Locale.Tr "create_new"}}</span>
107107
</span>
108-
<div class="menu left">
108+
<div class="menu">
109109
<a class="item" href="{{AppSubUrl}}/repo/create">
110110
{{svg "octicon-plus"}} {{ctx.Locale.Tr "new_repo"}}
111111
</a>

templates/repo/issue/labels/label_list.tmpl

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
<h4 class="ui top attached header">
22
{{ctx.Locale.Tr "repo.issues.label_count" .NumLabels}}
33
<div class="ui right">
4-
<div class="ui secondary menu">
5-
<!-- Sort -->
6-
<div class="item ui jump dropdown tw-py-2">
7-
<span class="text">
8-
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
9-
</span>
10-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
11-
<div class="menu">
12-
<a class="{{if or (eq .SortType "alphabetically") (not .SortType)}}active {{end}}item" href="?sort=alphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
13-
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="?sort=reversealphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
14-
<a class="{{if eq .SortType "leastissues"}}active {{end}}item" href="?sort=leastissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}</a>
15-
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="?sort=mostissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>
16-
</div>
4+
<!-- Sort -->
5+
<div class="item ui jump dropdown tw-py-2">
6+
<span class="text">
7+
{{ctx.Locale.Tr "repo.issues.filter_sort"}}
8+
</span>
9+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
10+
<div class="menu">
11+
<a class="{{if or (eq .SortType "alphabetically") (not .SortType)}}active {{end}}item" href="?sort=alphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.alphabetically"}}</a>
12+
<a class="{{if eq .SortType "reversealphabetically"}}active {{end}}item" href="?sort=reversealphabetically&state={{$.State}}">{{ctx.Locale.Tr "repo.issues.label.filter_sort.reverse_alphabetically"}}</a>
13+
<a class="{{if eq .SortType "leastissues"}}active {{end}}item" href="?sort=leastissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_issues"}}</a>
14+
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="?sort=mostissues&state={{$.State}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>
1715
</div>
1816
</div>
1917
</div> <!-- filter menu -->

web_src/css/modules/header.css

-6
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,6 @@ h4.ui.header .sub.header {
134134
font-weight: var(--font-weight-normal);
135135
}
136136

137-
/* open dropdown menus to the left in right-attached headers */
138-
.ui.attached.header > .ui.right .ui.dropdown .menu {
139-
right: 0;
140-
left: auto;
141-
}
142-
143137
/* if a .top.attached.header is followed by a .segment, add some margin */
144138
.ui.segments + .ui.top.attached.header,
145139
.ui.attached.segment + .ui.top.attached.header {

web_src/css/modules/navbar.css

+15-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,26 @@
1919
margin: 0;
2020
display: flex;
2121
align-items: center;
22+
gap: 5px;
2223
}
2324

2425
#navbar-logo {
2526
margin: 0;
2627
}
2728

29+
.navbar-left > .item,
30+
.navbar-right > .item {
31+
color: var(--color-nav-text);
32+
position: relative;
33+
text-decoration: none;
34+
line-height: var(--line-height-default);
35+
flex: 0 0 auto;
36+
font-weight: var(--font-weight-normal);
37+
align-items: center;
38+
padding: .78571429em .92857143em;
39+
border-radius: .28571429rem;
40+
}
41+
2842
#navbar .item {
2943
min-height: 36px;
3044
min-width: 36px;
@@ -33,10 +47,6 @@
3347
display: flex;
3448
}
3549

36-
#navbar > .menu > .item {
37-
color: var(--color-nav-text);
38-
}
39-
4050
#navbar .dropdown .item {
4151
justify-content: stretch;
4252
}
@@ -70,7 +80,7 @@
7080
}
7181
#navbar .navbar-mobile-right {
7282
display: flex;
73-
margin-left: auto !important;
83+
margin: 0 0 0 auto !important;
7484
width: auto !important;
7585
}
7686
#navbar .navbar-mobile-right > .item {

web_src/js/components/DiffCommitSelector.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default {
202202
>
203203
<svg-icon name="octicon-git-commit"/>
204204
</button>
205-
<div class="menu left transition" id="diff-commit-selector-menu" :class="{visible: menuVisible}" v-show="menuVisible" v-cloak :aria-expanded="menuVisible ? 'true': 'false'">
205+
<div class="left menu" id="diff-commit-selector-menu" :class="{visible: menuVisible}" v-show="menuVisible" v-cloak :aria-expanded="menuVisible ? 'true': 'false'">
206206
<div class="loading-indicator is-loading" v-if="isLoading"/>
207207
<div v-if="!isLoading" class="vertical item" id="diff-commit-list-show-all" role="menuitem" @keydown.enter="showAllChanges()" @click="showAllChanges()">
208208
<div class="gt-ellipsis">

web_src/js/modules/fomantic/dropdown.js

+16
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,22 @@ function delegateOne($dropdown) {
9494
updateSelectionLabel($label[0]);
9595
return $label;
9696
});
97+
98+
const oldSet = dropdownCall('internal', 'set');
99+
const oldSetDirection = oldSet.direction;
100+
oldSet.direction = function($menu) {
101+
oldSetDirection.call(this, $menu);
102+
const classNames = dropdownCall('setting', 'className');
103+
$menu = $menu || $dropdown.find('> .menu');
104+
const elMenu = $menu[0];
105+
// detect whether the menu is outside the viewport, and adjust the position
106+
// there is a bug in fomantic's builtin `direction` function, in some cases (when the menu width is only a little larger) it wrongly opens the menu at right and triggers the scrollbar.
107+
elMenu.classList.add(classNames.loading);
108+
if (elMenu.getBoundingClientRect().right > document.documentElement.clientWidth) {
109+
elMenu.classList.add(classNames.leftward);
110+
}
111+
elMenu.classList.remove(classNames.loading);
112+
};
97113
}
98114

99115
// for static dropdown elements (generated by server-side template), prepare them with necessary aria attributes

0 commit comments

Comments
 (0)