Improve clickoutside to handle right clicks properly
This commit is contained in:
parent
54621b1539
commit
80cbd70687
|
@ -15,6 +15,9 @@ let clickHandlers = []
|
|||
* Handle a body click event
|
||||
*/
|
||||
const handleClick = event => {
|
||||
// Treat right clicks (context menu events) as normal clicks
|
||||
const eventType = event.type === "contextmenu" ? "click" : event.type
|
||||
|
||||
// Ignore click if this is an ignored class
|
||||
if (event.target.closest('[data-ignore-click-outside="true"]')) {
|
||||
return
|
||||
|
@ -28,7 +31,7 @@ const handleClick = event => {
|
|||
// Process handlers
|
||||
clickHandlers.forEach(handler => {
|
||||
// Check that we're the right kind of click event
|
||||
if (handler.allowedType && event.type !== handler.allowedType) {
|
||||
if (handler.allowedType && eventType !== handler.allowedType) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -51,6 +54,7 @@ const handleClick = event => {
|
|||
}
|
||||
document.documentElement.addEventListener("click", handleClick, true)
|
||||
document.documentElement.addEventListener("mousedown", handleClick, true)
|
||||
document.documentElement.addEventListener("contextmenu", handleClick, true)
|
||||
|
||||
/**
|
||||
* Adds or updates a click handler
|
||||
|
|
|
@ -101,11 +101,10 @@
|
|||
|
||||
<style>
|
||||
.wrapper {
|
||||
flex: 0 0 400px;
|
||||
flex: 0 0 100px;
|
||||
margin: -28px -40px -40px -40px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--background);
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import { getContext, onMount } from "svelte"
|
||||
import { Icon, Popover, clickOutside } from "@budibase/bbui"
|
||||
import { Icon } from "@budibase/bbui"
|
||||
import GridPopover from "../overlays/GridPopover.svelte"
|
||||
|
||||
const { visibleColumns, scroll, width, subscribe } = getContext("grid")
|
||||
|
||||
|
@ -32,23 +33,18 @@
|
|||
>
|
||||
<Icon name="Add" />
|
||||
</div>
|
||||
<Popover
|
||||
bind:open
|
||||
{anchor}
|
||||
align={$visibleColumns.length ? "right" : "left"}
|
||||
offset={0}
|
||||
popoverTarget={document.getElementById(`add-column-button`)}
|
||||
customZindex={50}
|
||||
>
|
||||
<div
|
||||
use:clickOutside={() => {
|
||||
open = false
|
||||
}}
|
||||
class="content"
|
||||
{#if open}
|
||||
<GridPopover
|
||||
{anchor}
|
||||
align={$visibleColumns.length ? "right" : "left"}
|
||||
on:close={close}
|
||||
maxHeight={null}
|
||||
>
|
||||
<slot />
|
||||
</div>
|
||||
</Popover>
|
||||
<div class="content">
|
||||
<slot />
|
||||
</div>
|
||||
</GridPopover>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.add {
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
export let maxWidth = PopoverMaxWidth
|
||||
export let maxHeight = PopoverMaxHeight
|
||||
export let align = "left"
|
||||
export let open = true
|
||||
|
||||
const { gridID } = getContext("grid")
|
||||
const dispatch = createEventDispatcher()
|
||||
|
@ -35,7 +36,7 @@
|
|||
</script>
|
||||
|
||||
<Popover
|
||||
open
|
||||
{open}
|
||||
{anchor}
|
||||
{align}
|
||||
portalTarget="#{gridID} .grid-popover-container"
|
||||
|
|
Loading…
Reference in New Issue