diff --git a/src/web/stylesheets/layout/_io.css b/src/web/stylesheets/layout/_io.css index 0146bf27..de639753 100755 --- a/src/web/stylesheets/layout/_io.css +++ b/src/web/stylesheets/layout/_io.css @@ -478,6 +478,11 @@ background-color: #ddd } +/* Change color of dropup links on focus */ +.cm-status-bar-select-content a:focus { + background-color: #ddd; +} + /* Change the background color of the dropup button when the dropup content is shown */ .cm-status-bar-select:hover .cm-status-bar-select-btn { background-color: #f1f1f1; diff --git a/src/web/utils/statusBar.mjs b/src/web/utils/statusBar.mjs index 1adcd5be..b4054aea 100644 --- a/src/web/utils/statusBar.mjs +++ b/src/web/utils/statusBar.mjs @@ -53,9 +53,26 @@ class StatusBarPanel { dom.appendChild(rhs); // Event listeners - dom.querySelectorAll(".cm-status-bar-select-btn").forEach( - el => el.addEventListener("click", this.showDropUp.bind(this), false) + const eventHandler = this.showDropUp.bind(this); + + dom.querySelectorAll(".cm-status-bar-select-btn").forEach((el) => { + el.addEventListener("click", eventHandler, false); + }); + dom.querySelectorAll(".cm-status-bar-select-btn").forEach((el) => { + el.addEventListener("keydown", eventHandler, false); + }); + + const selectContent = dom.querySelectorAll( + ".cm-status-bar-select-content" ); + + selectContent.forEach((el) => { + const aTags = el.getElementsByTagName("a"); + + for (let i = 0; i < aTags.length; i++) { + aTags[i].addEventListener("keydown", arrowNav, false); + } + }); dom.querySelector(".eol-select").addEventListener("click", this.eolSelectClick.bind(this), false); dom.querySelector(".chr-enc-select").addEventListener("click", this.chrEncSelectClick.bind(this), false); dom.querySelector(".cm-status-bar-filter-input").addEventListener("keyup", this.chrEncFilter.bind(this), false); @@ -64,26 +81,30 @@ class StatusBarPanel { } /** - * Handler for dropup clicks + * Handler for dropup clicks/Enter press * Shows/Hides the dropup * @param {Event} e */ showDropUp(e) { - const el = e.target - .closest(".cm-status-bar-select") - .querySelector(".cm-status-bar-select-content"); - const btn = e.target.closest(".cm-status-bar-select-btn"); + if (e.type === "click" || e.key === "Enter"|| e.key === " ") { + const el = e.target + .closest(".cm-status-bar-select") + .querySelector(".cm-status-bar-select-content"); + const btn = e.target.closest(".cm-status-bar-select-btn"); - if (btn.classList.contains("disabled")) return; + if (btn.classList.contains("disabled")) return; - el.classList.add("show"); + el.classList.add("show"); - // Focus the filter input if present - const filter = el.querySelector(".cm-status-bar-filter-input"); - if (filter) filter.focus(); + // Focus the filter input if present + const filter = el.querySelector(".cm-status-bar-filter-input"); + if (filter) filter.focus(); - // Set up a listener to close the menu if the user clicks outside of it - hideOnClickOutside(el, e); + // Set up a listener to close the menu if the user clicks outside of it + hideOnClickOutside(el, e); + // Set up a listener to close the menu if the user presses key outside of it + hideOnMoveFocus(el, e); + } } /** @@ -209,6 +230,7 @@ class StatusBarPanel { } } + /** * Sets the current EOL separator in the status bar * @param {EditorState} state @@ -344,11 +366,11 @@ class StatusBarPanel { */ constructLHS() { return ` - + abc - + sort @@ -386,18 +408,18 @@ class StatusBarPanel { } return ` -