Skip to content

Commit

Permalink
Close old context menus on open new context menu
Browse files Browse the repository at this point in the history
Make sure that multiple context menus can't be open at the same time.
  • Loading branch information
seancolsen committed Mar 22, 2022
1 parent 8dce989 commit 8e89315
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ export default function clickOffBounds(
}
}

document.body.addEventListener('click', outOfBoundsListener, true);
document.body.addEventListener('pointerdown', outOfBoundsListener, true);

function update(opts: Options) {
callback = opts.callback;
references = opts.references;
}

function destroy() {
document.body.removeEventListener('click', outOfBoundsListener, true);
document.body.removeEventListener('pointerdown', outOfBoundsListener, true);
}

return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<script>
import { faFillDrip, faPlus } from '@fortawesome/free-solid-svg-icons';
import {
faFillDrip,
faPlus,
faTimes,
} from '@fortawesome/free-solid-svg-icons';
import { Meta, Story } from '@storybook/addon-svelte-csf';
import MenuItem from '@mathesar-component-library-dir/menu/MenuItem.svelte';
import Checkbox from '@mathesar-component-library-dir/checkbox/Checkbox.svelte';
Expand Down Expand Up @@ -42,6 +46,13 @@
</ContextMenu>
</div>

<div class="box with-context" has-background>
<p>This box <em>also</em> has a context menu.</p>
<ContextMenu>
<MenuItem icon={{ data: faTimes }}>I don't do anything</MenuItem>
</ContextMenu>
</div>

<div class="box without-context">
<p>This box does <em>not</em> have a context menu.</p>
</div>
Expand Down

0 comments on commit 8e89315

Please sign in to comment.