Skip to content

Fix always expanded "More" dropdown menu - #2359

Merged
busches merged 2 commits into
refined-github:masterfrom
kidonng:fix-dropdown
Aug 21, 2019
Merged

busches merged 2 commits into
refined-github:masterfrom
kidonng:fix-dropdown

Conversation

@kidonng

@kidonng kidonng commented Aug 21, 2019 •

Copy link
Copy Markdown
Member

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

@yakov116

Copy link
Copy Markdown
Member

@sindresorhus @fregante please merge...

@jetersen

Copy link
Copy Markdown
Contributor

@kidonng you could add closes #2358 😆

@kidonng

kidonng commented Aug 21, 2019

Copy link
Copy Markdown
Member Author

@Casz Oh I guess I can only close it when creating the PR but never mind

@jetersen

Copy link
Copy Markdown
Contributor

GitHub is finicky you have to preface it with closes https://help.github.com/en/articles/closing-issues-using-keywords#closing-multiple-issues

Closes #2357 closes #2358

@kidonng

kidonng commented Aug 21, 2019

Copy link
Copy Markdown
Member Author

@Casz Didn't know that, thanks for the information!

@kidonng kidonng changed the title fix always expanded "More" dropdown Fix always expanded "More" dropdown menu Aug 21, 2019
@truongnmt

Copy link
Copy Markdown

Why we have to change from button to summary? 🤔

@matschaffer

Copy link
Copy Markdown

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

@yolopunk

Copy link
Copy Markdown

Why we have to change from button to summary? 🤔

Absolutely, this is over design.

@matschaffer

Copy link
Copy Markdown

@yolopunk @truongnmt

For some reason using won't open the dropdown, I have read GitHub's code for some time but can't figure out why, so changed it to and everything looks fine.

Pretty sure @kidonng meant <summary> there, not <span>

Comment thread source/features/more-dropdown.tsx Resolved
Comment thread source/features/more-dropdown.tsx Resolved

@ChristianVermeulen ChristianVermeulen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't give a shit, this thing is annoying as fuck! Merge it already and figure out prettiness later! 😂

@kidonng

kidonng commented Aug 21, 2019 •

Copy link
Copy Markdown
Member Author

For those who wonder how the dropdown works:

(connectedCallback is fired when the <details-menu> element is added to DOM)

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));

@kidonng

kidonng commented Aug 21, 2019 •

Copy link
Copy Markdown
Member Author

@truongnmt @yolopunk @matschaffer I didn't change <button> to <summary>, I wrapped the <button> with <summary> (which is needed for the dropdown to work, see the code above) but found that for some reason it didn't work, so I changed the <button> to <span> instead.

Hmmm... after adopting @mobilutz's advice this does look like <button> to <summary>... but I think this is not the point.

@leggsimon

Copy link
Copy Markdown
Contributor

@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 busches left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Tested on GH with a repo I have settings on and do not and the same on GHE.

@busches
busches merged commit 9bf310a into refined-github:master Aug 21, 2019
@yakov116

Copy link
Copy Markdown
Member

@busches can you run hotfix from travis?

@busches

busches commented Aug 21, 2019

Copy link
Copy Markdown
Member

@busches can you run hotfix from travis?

Not to my knowledge, need @fregante or @sindresorhus for that.

@notlmn

notlmn commented Aug 21, 2019

Copy link
Copy Markdown
Contributor

Thanks for the fix @kidonng.


@busches can you run hotfix from travis?

Triggered a new build on Travis, AMO updated with 19.8.21 and the same should be reflected on Chrome Web Store soon.

@jetersen

jetersen commented Aug 21, 2019 •

Copy link
Copy Markdown
Contributor

I was able to update the extension in Chrome already.
Go here chrome://extensions/?id=hlepfoohegkhhmjieoechaddaejaokhf and click update.

@fregante

Copy link
Copy Markdown
Member

Thanks all for the quick fix. Sindre and I are both AFK

@fregante

Copy link
Copy Markdown
Member

@busches I think all collaborators can push a hotfix on Travis by triggering a manual build.

@busches

busches commented Aug 22, 2019

Copy link
Copy Markdown
Member

@fregante, ah I see the option now, TIL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Bug: "More" dropdown always expanded