Fix Picker Interaction with the Outside Click Action
This commit is contained in:
parent
55a3ea4add
commit
d2997b3357
|
@ -119,6 +119,13 @@
|
||||||
|
|
||||||
return "var(--spectrum-global-color-static-gray-900)"
|
return "var(--spectrum-global-color-static-gray-900)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleOutsideClick = event => {
|
||||||
|
if (open) {
|
||||||
|
event.stopPropagation()
|
||||||
|
open = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -131,7 +138,7 @@
|
||||||
</div>
|
</div>
|
||||||
{#if open}
|
{#if open}
|
||||||
<div
|
<div
|
||||||
use:clickOutside={() => (open = false)}
|
use:clickOutside={handleOutsideClick}
|
||||||
transition:fly={{ y: -20, duration: 200 }}
|
transition:fly={{ y: -20, duration: 200 }}
|
||||||
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
||||||
class:spectrum-Popover--align-right={alignRight}
|
class:spectrum-Popover--align-right={alignRight}
|
||||||
|
|
|
@ -85,7 +85,7 @@
|
||||||
class:is-invalid={!!error}
|
class:is-invalid={!!error}
|
||||||
class:is-open={open}
|
class:is-open={open}
|
||||||
aria-haspopup="listbox"
|
aria-haspopup="listbox"
|
||||||
on:mousedown={onClick}
|
on:click={onClick}
|
||||||
>
|
>
|
||||||
{#if fieldIcon}
|
{#if fieldIcon}
|
||||||
<span class="option-extra">
|
<span class="option-extra">
|
||||||
|
|
|
@ -87,6 +87,20 @@
|
||||||
updateValue(event.target.value)
|
updateValue(event.target.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handlePrimaryOutsideClick = event => {
|
||||||
|
if (primaryOpen) {
|
||||||
|
event.stopPropagation()
|
||||||
|
primaryOpen = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleSecondaryOutsideClick = event => {
|
||||||
|
if (secondaryOpen) {
|
||||||
|
event.stopPropagation()
|
||||||
|
secondaryOpen = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
@ -148,7 +162,7 @@
|
||||||
</div>
|
</div>
|
||||||
{#if primaryOpen}
|
{#if primaryOpen}
|
||||||
<div
|
<div
|
||||||
use:clickOutside={() => (primaryOpen = false)}
|
use:clickOutside={handlePrimaryOutsideClick}
|
||||||
transition:fly|local={{ y: -20, duration: 200 }}
|
transition:fly|local={{ y: -20, duration: 200 }}
|
||||||
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
||||||
class:auto-width={autoWidth}
|
class:auto-width={autoWidth}
|
||||||
|
@ -256,7 +270,7 @@
|
||||||
{disabled}
|
{disabled}
|
||||||
class:is-open={secondaryOpen}
|
class:is-open={secondaryOpen}
|
||||||
aria-haspopup="listbox"
|
aria-haspopup="listbox"
|
||||||
on:mousedown={onClickSecondary}
|
on:click={onClickSecondary}
|
||||||
>
|
>
|
||||||
{#if secondaryFieldIcon}
|
{#if secondaryFieldIcon}
|
||||||
<span class="option-left">
|
<span class="option-left">
|
||||||
|
@ -281,7 +295,7 @@
|
||||||
</button>
|
</button>
|
||||||
{#if secondaryOpen}
|
{#if secondaryOpen}
|
||||||
<div
|
<div
|
||||||
use:clickOutside={() => (secondaryOpen = false)}
|
use:clickOutside={handleSecondaryOutsideClick}
|
||||||
transition:fly|local={{ y: -20, duration: 200 }}
|
transition:fly|local={{ y: -20, duration: 200 }}
|
||||||
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
||||||
style="width: 30%"
|
style="width: 30%"
|
||||||
|
|
|
@ -50,6 +50,13 @@
|
||||||
dispatch("change", value)
|
dispatch("change", value)
|
||||||
open = false
|
open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleOutsideClick = event => {
|
||||||
|
if (open) {
|
||||||
|
event.stopPropagation()
|
||||||
|
open = false
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
@ -64,7 +71,7 @@
|
||||||
</div>
|
</div>
|
||||||
{#if open}
|
{#if open}
|
||||||
<div
|
<div
|
||||||
use:clickOutside={() => (open = false)}
|
use:clickOutside={handleOutsideClick}
|
||||||
transition:fly={{ y: -20, duration: 200 }}
|
transition:fly={{ y: -20, duration: 200 }}
|
||||||
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
||||||
class:spectrum-Popover--align-right={alignRight}
|
class:spectrum-Popover--align-right={alignRight}
|
||||||
|
|
Loading…
Reference in New Issue