Repository navigation
Fix always expanded "More" dropdown menu - #2359
Conversation
|
@sindresorhus @fregante please merge... |
|
@Casz Oh I guess I can only close it when creating the PR but never mind |
|
GitHub is finicky you have to preface it with closes https://help.github.com/en/articles/closing-issues-using-keywords#closing-multiple-issues |
|
@Casz Didn't know that, thanks for the information! |
|
Why we have to change from |
|
Did an unpacked build (per https://github.com/sindresorhus/refined-github/blob/master/contributing.md) from this PR and seems to be working great so far |
Absolutely, this is over design. |
Pretty sure @kidonng meant |
ChristianVermeulen
left a comment
There was a problem hiding this comment.
I don't give a shit, this thing is annoying as fuck! Merge it already and figure out prettiness later! 😂
|
For those who wonder how the dropdown works: ( Line 916-1170 from https://github.githubassets.com/assets/github-bootstrap-4b4ca38b.js (Formatted via Chrome DevTools)class DetailsMenuElement extends HTMLElement {
constructor() {
super()
}
get preload() {
return this.hasAttribute("preload")
}
set preload(e) {
e ? this.setAttribute("preload", "") : this.removeAttribute("preload")
}
get src() {
return this.getAttribute("src") || ""
}
set src(e) {
this.setAttribute("src", e)
}
connectedCallback() {
this.setAttribute("role", "menu");
const e = this.parentElement;
if (!e)
return;
const t = e.querySelector("summary");
t && t.setAttribute("aria-haspopup", "menu"),
e.addEventListener("click", Qt),
e.addEventListener("change", Qt),
e.addEventListener("keydown", en),
e.addEventListener("toggle", Vt, {
once: !0
}),
e.addEventListener("toggle", Yt),
this.preload && e.addEventListener("mouseover", Vt, {
once: !0
});
const n = [Kt(e)];
zt.set(this, {
details: e,
subscriptions: n,
loaded: !1
})
}
disconnectedCallback() {
const e = zt.get(this);
if (!e)
return;
zt.delete(this);
const t = e.details
, n = e.subscriptions;
for (const s of n)
s.unsubscribe();
t.removeEventListener("click", Qt),
t.removeEventListener("change", Qt),
t.removeEventListener("keydown", en),
t.removeEventListener("toggle", Vt, {
once: !0
}),
t.removeEventListener("toggle", Yt),
t.removeEventListener("mouseover", Vt, {
once: !0
})
}
}
const zt = new WeakMap;
function Vt(e) {
const t = e.currentTarget;
if (!(t instanceof Element))
return;
const n = t.querySelector("details-menu");
if (!n)
return;
const s = n.getAttribute("src");
if (!s)
return;
const o = zt.get(n);
if (!o)
return;
if (o.loaded)
return;
o.loaded = !0;
const i = n.querySelector("include-fragment");
i && !i.hasAttribute("src") && (i.addEventListener("loadend", ()=>Xt(t)),
i.setAttribute("src", s))
}
function Kt(e) {
let t = !1;
const n = ()=>t = !0
, s = ()=>t = !1
, o = ()=>{
Xt(e),
e.hasAttribute("open") && !t && function(e) {
const t = document.activeElement;
if (t && tn(t) && e.contains(t))
return;
const n = Jt(e, !0);
n && n.focus()
}(e)
}
;
return e.addEventListener("mousedown", n),
e.addEventListener("keydown", s),
e.addEventListener("toggle", o),
{
unsubscribe: ()=>{
e.removeEventListener("mousedown", n),
e.removeEventListener("keydown", s),
e.removeEventListener("toggle", o)
}
}
}
function Yt(e) {
const t = e.currentTarget;
if (t instanceof Element && t.hasAttribute("open"))
for (const n of document.querySelectorAll("details[open] > details-menu")) {
const e = n.closest("details");
e && e !== t && !e.contains(t) && e.removeAttribute("open")
}
}
function Xt(e) {
if (!e.hasAttribute("open"))
return;
const t = e.querySelector("[autofocus]");
t && t.focus()
}
function Jt(e, t) {
const n = Array.from(e.querySelectorAll('[role^="menuitem"]:not([hidden]):not([disabled]):not([aria-disabled="true"])'))
, s = document.activeElement
, o = n.indexOf(s)
, i = t ? n[o + 1] : n[o - 1]
, r = t ? n[0] : n[n.length - 1];
return i || r
}
const Gt = navigator.userAgent.match(/Macintosh/);
function Qt(e) {
const t = e.target;
if (!(t instanceof Element))
return;
const n = e.currentTarget;
if (n instanceof Element && t.closest("details") === n)
if ("click" === e.type) {
const e = t.closest('[role="menuitem"], [role="menuitemradio"]')
, s = e && "LABEL" === e.tagName && e.querySelector("input");
e && !s && Zt(e, n)
} else if ("change" === e.type) {
const e = t.closest('[role="menuitemradio"], [role="menuitemcheckbox"]');
e && Zt(e, n)
}
}
function Zt(e, t) {
if (e.hasAttribute("disabled") || "true" === e.getAttribute("aria-disabled"))
return;
const n = e.closest("details-menu");
n && n.dispatchEvent(new CustomEvent("details-menu-select",{
cancelable: !0,
detail: {
relatedTarget: e
}
})) && (!function(e, t) {
const n = t.querySelector("[data-menu-button]");
if (!n)
return;
const s = function(e) {
if (!e)
return null;
const t = e.hasAttribute("data-menu-button-text") ? e : e.querySelector("[data-menu-button-text]");
return t ? t.getAttribute("data-menu-button-text") || t.textContent : null
}(e);
if (s)
n.textContent = s;
else {
const t = function(e) {
if (!e)
return null;
const t = e.hasAttribute("data-menu-button-contents") ? e : e.querySelector("[data-menu-button-contents]");
return t ? t.innerHTML : null
}(e);
t && (n.innerHTML = t)
}
}(e, t),
function(e, t) {
for (const n of t.querySelectorAll('[role="menuitemradio"], [role="menuitemcheckbox"]')) {
const t = n.querySelector('input[type="radio"], input[type="checkbox"]');
let s = n === e;
t instanceof HTMLInputElement && (s = t.indeterminate ? "mixed" : t.checked),
n.setAttribute("aria-checked", s.toString())
}
}(e, t),
"menuitemcheckbox" !== e.getAttribute("role") && nn(t),
n.dispatchEvent(new CustomEvent("details-menu-selected",{
detail: {
relatedTarget: e
}
})))
}
function en(e) {
const t = e.currentTarget;
if (!(t instanceof Element))
return;
const n = e.target instanceof Element && "SUMMARY" === e.target.tagName;
if (!t.querySelector("details[open]"))
switch (e.key) {
case "Escape":
t.hasAttribute("open") && (nn(t),
e.preventDefault(),
e.stopPropagation());
break;
case "ArrowDown":
{
n && !t.hasAttribute("open") && t.setAttribute("open", "");
const s = Jt(t, !0);
s && s.focus(),
e.preventDefault()
}
break;
case "ArrowUp":
{
n && !t.hasAttribute("open") && t.setAttribute("open", "");
const s = Jt(t, !1);
s && s.focus(),
e.preventDefault()
}
break;
case "n":
if (Gt && e.ctrlKey) {
const n = Jt(t, !0);
n && n.focus(),
e.preventDefault()
}
break;
case "p":
if (Gt && e.ctrlKey) {
const n = Jt(t, !1);
n && n.focus(),
e.preventDefault()
}
break;
case " ":
case "Enter":
{
const n = document.activeElement;
n && tn(n) && n.closest("details") === t && (e.preventDefault(),
e.stopPropagation(),
n.click())
}
}
}
function tn(e) {
const t = e.getAttribute("role");
return "menuitem" === t || "menuitemcheckbox" === t || "menuitemradio" === t
}
function nn(e) {
e.removeAttribute("open");
const t = e.querySelector("summary");
t && t.focus()
}
window.customElements.get("details-menu") || (window.DetailsMenuElement = DetailsMenuElement,
window.customElements.define("details-menu", DetailsMenuElement)); |
|
@truongnmt @yolopunk @matschaffer I didn't change Hmmm... after adopting @mobilutz's advice this does look like |
|
@ChristianVermeulen comments like that aren’t really helpful. If it’s bothering you that much you can disable this feature by right clicking on the Refined Github extension go to Options, scroll down and uncheck the “more-dropdown” feature. |
|
@busches can you run hotfix from travis? |
Not to my knowledge, need @fregante or @sindresorhus for that. |
|
I was able to update the extension in Chrome already. |
|
Thanks all for the quick fix. Sindre and I are both AFK |
|
@busches I think all collaborators can push a hotfix on Travis by triggering a manual build. |
|
@fregante, ah I see the option now, TIL. |
Closes #2357
Closes #2358
For some reason using
<button>won't open the dropdown, I have read GitHub's code for some time but can't figure out why, so changed it to<span>and everything looks fine.Test
This repo