mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-20 08:01:35 +00:00
Fix select click outside (#3162)
* feat(frontend): fix clickOutside when using portals * feat(frontend): fix clickOutside when using portals * feat(frontend): clean up
This commit is contained in:
@@ -681,7 +681,7 @@
|
||||
{/if}
|
||||
|
||||
{#if showClear}
|
||||
<button type="button" class="icon clear-select" on:click={handleClear}>
|
||||
<button type="button" class="icon clear-select" on:click|stopPropagation={handleClear}>
|
||||
<slot name="clear-icon">
|
||||
<ClearIcon />
|
||||
</slot>
|
||||
|
||||
@@ -116,10 +116,20 @@ export function validatePassword(password: string): boolean {
|
||||
return re.test(password)
|
||||
}
|
||||
|
||||
const portalDivs = ['app-editor-select']
|
||||
|
||||
export function clickOutside(node: Node, capture?: boolean): { destroy(): void } {
|
||||
const handleClick = (event: MouseEvent) => {
|
||||
if (node && !node.contains(<HTMLElement>event.target) && !event.defaultPrevented) {
|
||||
node.dispatchEvent(new CustomEvent<MouseEvent>('click_outside', { detail: event }))
|
||||
const target = event.target as HTMLElement
|
||||
|
||||
if (node && !node.contains(target) && !event.defaultPrevented) {
|
||||
const portalDivsSelector = portalDivs.map((id) => `#${id}`).join(', ')
|
||||
|
||||
const parent = target.closest(portalDivsSelector)
|
||||
|
||||
if (!parent) {
|
||||
node.dispatchEvent(new CustomEvent<MouseEvent>('click_outside', { detail: event }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user