mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Fix issue with dropdowns
This commit is contained in:
parent
c1adebf2da
commit
413ac6cf63
4 changed files with 14 additions and 14 deletions
|
@ -4,7 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import type { Readable } from "svelte/store";
|
import type { Readable } from "svelte/store";
|
||||||
import { hasContext, getContext, onMount, createEventDispatcher } from "svelte";
|
import { getContext, onMount, createEventDispatcher } from "svelte";
|
||||||
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
import { disabledKey, nightModeKey, dropdownKey } from "./contextKeys";
|
||||||
|
|
||||||
export let id: string;
|
export let id: string;
|
||||||
|
|
|
@ -19,25 +19,24 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
/* Normally dropdown and trigger are associated with a
|
/* Normally dropdown and trigger are associated with a
|
||||||
/* common ancestor with .dropdown class */
|
/* common ancestor with .dropdown class */
|
||||||
function createDropdown(button: HTMLElement): void {
|
function createDropdown(event: CustomEvent): void {
|
||||||
|
const button: HTMLButtonElement = event.detail.button;
|
||||||
|
|
||||||
/* Prevent focus on menu activation */
|
/* Prevent focus on menu activation */
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
Object.defineProperty(button, "focus", { value: noop });
|
Object.defineProperty(button, "focus", { value: noop });
|
||||||
|
|
||||||
/* Set custom menu without using .dropdown
|
|
||||||
* Rendering the menu here would cause the menu to
|
|
||||||
* be displayed outside of the visible area */
|
|
||||||
|
|
||||||
const dropdown = new Dropdown(button);
|
|
||||||
|
|
||||||
const menu = (button.getRootNode() as Document) /* or shadow root */
|
const menu = (button.getRootNode() as Document) /* or shadow root */
|
||||||
.getElementById(menuId);
|
.getElementById(menuId);
|
||||||
|
|
||||||
if (!menu) {
|
if (!menu) {
|
||||||
console.log(`Could not find menu "${menuId}" for dropdown menu.`);
|
console.log(`Could not find menu "${menuId}" for dropdown menu.`);
|
||||||
}
|
} else {
|
||||||
|
const dropdown = new Dropdown(button);
|
||||||
|
|
||||||
(dropdown as any)._menu = menu;
|
/* Set custom menu without using common element with .dropdown */
|
||||||
|
(dropdown as any)._menu = menu;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
</WithState>
|
</WithState>
|
||||||
|
|
||||||
<WithDropdownMenu let:createDropdown let:menuId>
|
<WithDropdownMenu let:createDropdown let:menuId>
|
||||||
<IconButton on:mount={(event) => createDropdown(event.detail.button)}>
|
<IconButton on:mount={createDropdown}>
|
||||||
{@html listOptionsIcon}
|
{@html listOptionsIcon}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
|
@ -148,11 +148,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
|
||||||
<ButtonGroup id="indentation" {api}>
|
<ButtonGroup id="indentation" {api}>
|
||||||
<IconButton on:click={outdentListItem} tooltip={tr.editingOutdent}>
|
<IconButton on:click={outdentListItem} tooltip={tr.editingOutdent()}>
|
||||||
{@html outdentIcon}
|
{@html outdentIcon}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
|
|
||||||
<IconButton on:click={indentListItem} tooltip={tr.editingIndent}>
|
<IconButton on:click={indentListItem} tooltip={tr.editingIndent()}>
|
||||||
{@html indentIcon}
|
{@html indentIcon}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
|
|
@ -115,7 +115,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<WithShortcut shortcut="Control+Shift+KeyX" let:createShortcut let:shortcutLabel>
|
<WithShortcut shortcut="Control+Shift+KeyX" let:createShortcut let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)}
|
tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)}
|
||||||
on:click={onHtmlEdit}>
|
on:click={onHtmlEdit}
|
||||||
|
on:mount={createShortcut}>
|
||||||
{@html xmlIcon}
|
{@html xmlIcon}
|
||||||
</IconButton>
|
</IconButton>
|
||||||
</WithShortcut>
|
</WithShortcut>
|
||||||
|
|
Loading…
Reference in a new issue