mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-09 09:20:54 +00:00
Close nested menu on move to main menu (#2364)
Signed-off-by: Denis Bunakalya <denis.bunakalya@xored.com>
This commit is contained in:
parent
9451aafa82
commit
6cc79a0fcd
@ -14,7 +14,7 @@
|
|||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { afterUpdate, createEventDispatcher, onDestroy, onMount } from 'svelte'
|
import { afterUpdate, createEventDispatcher, onDestroy, onMount } from 'svelte'
|
||||||
import { generateId } from '@hcengineering/core'
|
import { generateId, Ref, Doc } from '@hcengineering/core'
|
||||||
import ui from '../plugin'
|
import ui from '../plugin'
|
||||||
import { closePopup, showPopup } from '../popups'
|
import { closePopup, showPopup } from '../popups'
|
||||||
import { Action } from '../types'
|
import { Action } from '../types'
|
||||||
@ -25,11 +25,13 @@
|
|||||||
|
|
||||||
export let actions: Action[] = []
|
export let actions: Action[] = []
|
||||||
export let ctx: any = undefined
|
export let ctx: any = undefined
|
||||||
|
export let popupCategory: Ref<Doc> | undefined = undefined
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const btns: HTMLElement[] = []
|
const btns: HTMLElement[] = []
|
||||||
let activeElement: HTMLElement
|
let activeElement: HTMLElement
|
||||||
const category = generateId()
|
const category = popupCategory || generateId()
|
||||||
|
const nextCategory = generateId()
|
||||||
|
|
||||||
const keyDown = (ev: KeyboardEvent): void => {
|
const keyDown = (ev: KeyboardEvent): void => {
|
||||||
if (ev.key === 'Tab') {
|
if (ev.key === 'Tab') {
|
||||||
@ -78,12 +80,14 @@
|
|||||||
closePopup(category)
|
closePopup(category)
|
||||||
})
|
})
|
||||||
|
|
||||||
function showActionPopup (action: Action, target: HTMLElement): void {
|
function showActionPopup (action: Action, target: HTMLElement, isPopupHidden?: boolean): void {
|
||||||
closePopup(category)
|
closePopup(category)
|
||||||
if (action.component !== undefined) {
|
closePopup(nextCategory)
|
||||||
|
|
||||||
|
if (action.component !== undefined && !isPopupHidden) {
|
||||||
showPopup(
|
showPopup(
|
||||||
action.component,
|
action.component,
|
||||||
action.props,
|
{ ...action.props, popupCategory: nextCategory },
|
||||||
{ getBoundingClientRect: () => target.getBoundingClientRect(), kind: 'submenu' },
|
{ getBoundingClientRect: () => target.getBoundingClientRect(), kind: 'submenu' },
|
||||||
(evt) => {
|
(evt) => {
|
||||||
dispatch('close')
|
dispatch('close')
|
||||||
@ -96,7 +100,7 @@
|
|||||||
function focusTarget (action: Action, target: HTMLElement, isPopupHidden?: boolean): void {
|
function focusTarget (action: Action, target: HTMLElement, isPopupHidden?: boolean): void {
|
||||||
if (focusSpeed && target !== activeElement) {
|
if (focusSpeed && target !== activeElement) {
|
||||||
activeElement = target
|
activeElement = target
|
||||||
!isPopupHidden && showActionPopup(action, target)
|
showActionPopup(action, target, isPopupHidden)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function clearFocus (): void {
|
export function clearFocus (): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user