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:
Faton Ramadani
2024-02-06 16:35:20 +01:00
committed by GitHub
parent a06112abc9
commit fc5a9b3f58
2 changed files with 13 additions and 3 deletions
@@ -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>
+12 -2
View File
@@ -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 }))
}
}
}