mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-11 09:35:49 +02:00
Merge pull request #20583 from calixteman/simplify_menu
Hide the menu container in changing it's visibility
This commit is contained in:
commit
23c7b1ac8e
11
web/menu.css
11
web/menu.css
@ -13,6 +13,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
button.hasPopupMenu {
|
||||||
|
&[aria-expanded="true"] + menu {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
&[aria-expanded="false"] + menu {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.popupMenu {
|
.popupMenu {
|
||||||
--menuitem-checkmark-icon: url(images/checkmark.svg);
|
--menuitem-checkmark-icon: url(images/checkmark.svg);
|
||||||
--menu-mark-icon-size: 0;
|
--menu-mark-icon-size: 0;
|
||||||
@ -75,6 +85,7 @@
|
|||||||
top: 1px;
|
top: 1px;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
|
||||||
background: var(--menu-bg);
|
background: var(--menu-bg);
|
||||||
background-blend-mode: var(--menu-background-blend-mode);
|
background-blend-mode: var(--menu-background-blend-mode);
|
||||||
|
|||||||
39
web/menu.js
39
web/menu.js
@ -56,7 +56,6 @@ class Menu {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const menu = this.#menu;
|
const menu = this.#menu;
|
||||||
menu.classList.toggle("hidden", true);
|
|
||||||
this.#triggeringButton.ariaExpanded = "false";
|
this.#triggeringButton.ariaExpanded = "false";
|
||||||
this.#openMenuAC.abort();
|
this.#openMenuAC.abort();
|
||||||
this.#openMenuAC = null;
|
this.#openMenuAC = null;
|
||||||
@ -82,7 +81,6 @@ class Menu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const menu = this.#menu;
|
const menu = this.#menu;
|
||||||
menu.classList.toggle("hidden", false);
|
|
||||||
this.#triggeringButton.ariaExpanded = "true";
|
this.#triggeringButton.ariaExpanded = "true";
|
||||||
this.#openMenuAC = new AbortController();
|
this.#openMenuAC = new AbortController();
|
||||||
const signal = AbortSignal.any([
|
const signal = AbortSignal.any([
|
||||||
@ -137,6 +135,13 @@ class Menu {
|
|||||||
.focus();
|
.focus();
|
||||||
stopEvent(e);
|
stopEvent(e);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
const char = e.key.toLocaleLowerCase();
|
||||||
|
this.#goToNextItem(e.target, true, item =>
|
||||||
|
item.textContent.trim().toLowerCase().startsWith(char)
|
||||||
|
);
|
||||||
|
stopEvent(e);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ signal, capture: true }
|
{ signal, capture: true }
|
||||||
@ -148,32 +153,38 @@ class Menu {
|
|||||||
});
|
});
|
||||||
this.#triggeringButton.addEventListener(
|
this.#triggeringButton.addEventListener(
|
||||||
"keydown",
|
"keydown",
|
||||||
ev => {
|
e => {
|
||||||
if (!this.#openMenuAC) {
|
switch (e.key) {
|
||||||
return;
|
case " ":
|
||||||
}
|
case "Enter":
|
||||||
switch (ev.key) {
|
|
||||||
case "ArrowDown":
|
case "ArrowDown":
|
||||||
case "Home":
|
case "Home":
|
||||||
|
if (!this.#openMenuAC) {
|
||||||
|
this.#triggeringButton.click();
|
||||||
|
}
|
||||||
this.#menuItems
|
this.#menuItems
|
||||||
.find(
|
.find(
|
||||||
item => !item.disabled && !item.classList.contains("hidden")
|
item => !item.disabled && !item.classList.contains("hidden")
|
||||||
)
|
)
|
||||||
.focus();
|
.focus();
|
||||||
stopEvent(ev);
|
stopEvent(e);
|
||||||
break;
|
break;
|
||||||
case "ArrowUp":
|
case "ArrowUp":
|
||||||
case "End":
|
case "End":
|
||||||
|
if (!this.#openMenuAC) {
|
||||||
|
this.#triggeringButton.click();
|
||||||
|
}
|
||||||
this.#menuItems
|
this.#menuItems
|
||||||
.findLast(
|
.findLast(
|
||||||
item => !item.disabled && !item.classList.contains("hidden")
|
item => !item.disabled && !item.classList.contains("hidden")
|
||||||
)
|
)
|
||||||
.focus();
|
.focus();
|
||||||
stopEvent(ev);
|
stopEvent(e);
|
||||||
break;
|
break;
|
||||||
case "Escape":
|
case "Escape":
|
||||||
this.#closeMenu();
|
this.#closeMenu();
|
||||||
stopEvent(ev);
|
stopEvent(e);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ signal }
|
{ signal }
|
||||||
@ -185,7 +196,7 @@ class Menu {
|
|||||||
* @param {HTMLElement} element
|
* @param {HTMLElement} element
|
||||||
* @param {boolean} forward
|
* @param {boolean} forward
|
||||||
*/
|
*/
|
||||||
#goToNextItem(element, forward) {
|
#goToNextItem(element, forward, check = () => true) {
|
||||||
const index =
|
const index =
|
||||||
this.#lastIndex === -1
|
this.#lastIndex === -1
|
||||||
? this.#menuItems.indexOf(element)
|
? this.#menuItems.indexOf(element)
|
||||||
@ -198,7 +209,11 @@ class Menu {
|
|||||||
i = (i + increment) % len
|
i = (i + increment) % len
|
||||||
) {
|
) {
|
||||||
const menuItem = this.#menuItems[i];
|
const menuItem = this.#menuItems[i];
|
||||||
if (!menuItem.disabled && !menuItem.classList.contains("hidden")) {
|
if (
|
||||||
|
!menuItem.disabled &&
|
||||||
|
!menuItem.classList.contains("hidden") &&
|
||||||
|
check(menuItem)
|
||||||
|
) {
|
||||||
menuItem.focus();
|
menuItem.focus();
|
||||||
this.#lastIndex = i;
|
this.#lastIndex = i;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -130,7 +130,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
<div id="viewsManagerTitle">
|
<div id="viewsManagerTitle">
|
||||||
<div id="viewsManagerSelector">
|
<div id="viewsManagerSelector">
|
||||||
<button
|
<button
|
||||||
class="toolbarButton viewsManagerButton"
|
class="toolbarButton viewsManagerButton hasPopupMenu"
|
||||||
type="button"
|
type="button"
|
||||||
id="viewsManagerSelectorButton"
|
id="viewsManagerSelectorButton"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
@ -141,7 +141,7 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
>
|
>
|
||||||
<span data-l10n-id="pdfjs-views-manager-view-selector-button-label"></span>
|
<span data-l10n-id="pdfjs-views-manager-view-selector-button-label"></span>
|
||||||
</button>
|
</button>
|
||||||
<menu id="viewsManagerSelectorOptions" role="listbox" class="popupMenu hidden withMark">
|
<menu id="viewsManagerSelectorOptions" role="listbox" class="popupMenu withMark">
|
||||||
<li>
|
<li>
|
||||||
<button id="thumbnailsViewMenu" role="option" type="button" tabindex="-1">
|
<button id="thumbnailsViewMenu" role="option" type="button" tabindex="-1">
|
||||||
<span data-l10n-id="pdfjs-views-manager-pages-option-label"></span>
|
<span data-l10n-id="pdfjs-views-manager-pages-option-label"></span>
|
||||||
@ -196,15 +196,16 @@ See https://github.com/adobe-type-tools/cmap-resources
|
|||||||
<div id="actionSelector">
|
<div id="actionSelector">
|
||||||
<button
|
<button
|
||||||
id="viewsManagerStatusActionButton"
|
id="viewsManagerStatusActionButton"
|
||||||
class="viewsManagerButton"
|
class="viewsManagerButton hasPopupMenu"
|
||||||
type="button"
|
type="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
aria-haspopup="menu"
|
aria-haspopup="menu"
|
||||||
aria-controls="viewsManagerStatusActionOptions"
|
aria-controls="viewsManagerStatusActionOptions"
|
||||||
|
aria-expanded="false"
|
||||||
>
|
>
|
||||||
<span data-l10n-id="pdfjs-views-manager-pages-status-action-button-label"></span>
|
<span data-l10n-id="pdfjs-views-manager-pages-status-action-button-label"></span>
|
||||||
</button>
|
</button>
|
||||||
<menu id="viewsManagerStatusActionOptions" class="popupMenu hidden">
|
<menu id="viewsManagerStatusActionOptions" class="popupMenu">
|
||||||
<li>
|
<li>
|
||||||
<button id="viewsManagerStatusActionCopy" class="noIcon" role="menuitem" type="button" tabindex="0">
|
<button id="viewsManagerStatusActionCopy" class="noIcon" role="menuitem" type="button" tabindex="0">
|
||||||
<span data-l10n-id="pdfjs-views-manager-pages-status-copy-button-label"></span>
|
<span data-l10n-id="pdfjs-views-manager-pages-status-copy-button-label"></span>
|
||||||
|
|||||||
@ -394,6 +394,7 @@
|
|||||||
|
|
||||||
#actionSelector {
|
#actionSelector {
|
||||||
height: 32px;
|
height: 32px;
|
||||||
|
min-width: 115px;
|
||||||
width: auto;
|
width: auto;
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
@ -425,8 +426,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
> .contextMenu {
|
> .popupMenu {
|
||||||
min-width: 115px;
|
width: auto;
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user