mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 03:18:24 +00:00 
			
		
		
		
	Prevent layout shift in <overflow-menu> items (#29831)
				
					
				
			There is a small layout shift in when active tab changes. Notice how the actions SVG is unstable:  This is because the active item with bold text is wider then the inactive one. I have applied [this trick](https://stackoverflow.com/a/32570813/808699) to prevent this layout shift. It's only active inside `<overflow-menu>` because I wanted to avoid changing HTML and doing it in regular JS would cause a flicker. I don't expect us to introduce other similar menus without `<overflow-menu>`, so that place is likely fine.  I also changed the weight from 500 to 600, slightly reduced horizontal padding, merged some tab-bar related CSS rules and a added a small margin below repo-header so it does not look so crammed against the buttons on top. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -127,6 +127,25 @@ 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, .ui.tabular.menu')) { | ||||
|       for (const item of this.querySelectorAll('.item')) { | ||||
|         for (const child of item.childNodes) { | ||||
|           if (child.nodeType === Node.TEXT_NODE) { | ||||
|             const text = child.textContent.trim(); // whitespace is insignificant inside flexbox | ||||
|             if (!text) continue; | ||||
|             const span = document.createElement('span'); | ||||
|             span.classList.add('resize-for-semibold'); | ||||
|             span.setAttribute('data-text', text); | ||||
|             span.textContent = text; | ||||
|             child.replaceWith(span); | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     // 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) => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user