Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make menu bar entries clickable by dragging from the header button and releasing on the entry #2164

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/src/components/floating-menus/MenuList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
on:click={() => !entry.disabled && onEntryClick(entry)}
on:pointerenter={() => !entry.disabled && onEntryPointerEnter(entry)}
on:pointerleave={() => !entry.disabled && onEntryPointerLeave(entry)}
on:mouseup={() => !entry.disabled && onEntryClick(entry)}
>
{#if entry.icon && drawIcon}
<IconLabel icon={entry.icon} class="entry-icon" />
Expand Down
18 changes: 14 additions & 4 deletions frontend/src/components/widgets/buttons/TextButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import TextLabel from "@graphite/components/widgets/labels/TextLabel.svelte";

let self: MenuList;
let isOpen = false;

// Note: IconButton should be used if only an icon, but no label, is desired.
// However, if multiple TextButton widgets are used in a group with only some having no label, this component is able to accommodate that.
Expand All @@ -28,7 +29,7 @@
$: menuListChildrenExists = (menuListChildren?.length ?? 0) > 0;

// Handles either a button click or, if applicable, the opening of the menu list floating menu
function onClick(e: MouseEvent) {
function onMouseDown(e: MouseEvent) {
// If there's no menu to open, trigger the action
if ((menuListChildren?.length ?? 0) === 0) {
// Call the action
Expand All @@ -41,10 +42,18 @@
// Focus the target so that keyboard inputs are sent to the dropdown
(e.target as HTMLElement | undefined)?.focus();

isOpen = !isOpen;
// Open the menu list floating menu
if (self) self.open = true;
if (self) self.open = isOpen;
else throw new Error("The menu bar floating menu has no reference to `self`");
}

function onRightClick(e: MouseEvent) {
e.preventDefault();
e.stopPropagation();
// close the menu
if (self) self.open = false;
}
</script>

<ConditionalWrapper condition={menuListChildrenExists} wrapperClass="text-button-container">
Expand All @@ -62,7 +71,8 @@
data-text-button
tabindex={disabled ? -1 : 0}
data-floating-menu-spawner={menuListChildrenExists ? "" : "no-hover-transfer"}
on:click={onClick}
on:mousedown={onMouseDown}
on:contextmenu={onRightClick}
>
{#if icon}
<IconLabel {icon} />
Expand All @@ -76,7 +86,7 @@
</button>
{#if menuListChildrenExists}
<MenuList
on:open={({ detail }) => self && (self.open = detail)}
on:open={({ detail }) => self && ((self.open = detail), (isOpen = !isOpen))}
open={self?.open || false}
entries={menuListChildren || []}
direction="Bottom"
Expand Down