Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent layout shift in <overflow-menu> items #29831

Merged
merged 12 commits into from
Mar 20, 2024
32 changes: 21 additions & 11 deletions web_src/css/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,19 @@ img.ui.avatar,
padding-bottom: 80px;
}

.ui.tabular.menu .active.item,
.ui.secondary.pointing.menu .active.item,
.size-for-semibold::before {
font-weight: var(--font-weight-semibold);
}

.size-for-semibold::before {
content: attr(data-text);
visibility: hidden;
display: block;
height: 0;
}

/* overwrite semantic width of containers inside the main page content div (div with class "page-content") */
.page-content .ui.ui.ui.container:not(.fluid) {
width: 1280px;
Expand Down Expand Up @@ -1835,15 +1848,6 @@ table th[data-sortt-desc] .svg {
border-color: var(--color-secondary);
}

.ui.tabular.menu .item {
padding: 11px 12px;
color: var(--color-text-light-2);
}

.ui.tabular.menu .item:hover {
color: var(--color-text);
}

.ui.tabular.menu .active.item,
.ui.tabular.menu .active.item:hover {
background: var(--color-body);
Expand All @@ -1860,14 +1864,20 @@ table th[data-sortt-desc] .svg {
border-color: var(--color-secondary);
}

.ui.tabular.menu .item,
.ui.secondary.pointing.menu .item {
padding: 11px 12px !important;
color: var(--color-text-light-2);
}

.ui.tabular.menu .item:hover,
.ui.secondary.pointing.menu a.item:hover {
color: var(--color-text);
}

.ui.secondary.pointing.menu .active.item,
.ui.secondary.pointing.menu .active.item:hover,
.ui.secondary.pointing.menu .dropdown.item:hover,
.ui.secondary.pointing.menu a.item:hover {
.ui.secondary.pointing.menu .dropdown.item:hover {
color: var(--color-text-dark);
}

Expand Down
1 change: 1 addition & 0 deletions web_src/css/repo/header.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
flex-flow: row wrap;
justify-content: space-between;
gap: 0.5rem;
margin-bottom: 4px;
}

.repo-header .flex-item {
Expand Down
20 changes: 20 additions & 0 deletions web_src/js/webcomponents/overflow-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,26 @@ window.customElements.define('overflow-menu', class extends HTMLElement {
});

init() {
// for horizontal menus where fomantic boldens active items, prevent this bold text from
// enlarging the menu's active item replacing the text node with a div that renders a
// invisible pseudo-element that enlarges the box.
if (this.matches('.ui.secondary.pointing.menu') || this.matches('.ui.tabular.menu')) {
silverwind marked this conversation as resolved.
Show resolved Hide resolved
for (const item of this.querySelectorAll('.item')) {
for (const child of item.childNodes) {
if (child.nodeType === Node.TEXT_NODE) {
const text = child.textContent.trim();
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
if (text) {
const div = document.createElement('div');
div.classList.add('size-for-semibold');
wxiaoguang marked this conversation as resolved.
Show resolved Hide resolved
div.setAttribute('data-text', text);
div.textContent = text;
child.replaceWith(div);
}
}
}
}
}

// ResizeObserver triggers on initial render, so we don't manually call `updateItems` here which
// also avoids a full-page FOUC in Firefox that happens when `updateItems` is called too soon.
this.resizeObserver = new ResizeObserver((entries) => {
Expand Down