mirror of
https://github.com/hcengineering/platform.git
synced 2025-06-09 01:10:17 +00:00
UBER-635-card-hotkeys (#4330)
Signed-off-by: Sergey Voytsehovich <syargreg@gmail.com>
This commit is contained in:
parent
7f6f5e28a6
commit
f972066df6
@ -22,7 +22,8 @@
|
|||||||
Scroller,
|
Scroller,
|
||||||
deviceOptionsStore as deviceInfo,
|
deviceOptionsStore as deviceInfo,
|
||||||
resizeObserver,
|
resizeObserver,
|
||||||
IconBack
|
IconBack,
|
||||||
|
getFocusManager
|
||||||
} from '@hcengineering/ui'
|
} from '@hcengineering/ui'
|
||||||
import { createEventDispatcher } from 'svelte'
|
import { createEventDispatcher } from 'svelte'
|
||||||
import presentation from '..'
|
import presentation from '..'
|
||||||
@ -50,8 +51,46 @@
|
|||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
|
const focusManager = getFocusManager()
|
||||||
|
|
||||||
let okProcessing = false
|
let okProcessing = false
|
||||||
$: headerDivide = hideContent && numberOfBlocks > 1
|
$: headerDivide = hideContent && numberOfBlocks > 1
|
||||||
|
|
||||||
|
function handleKeyDown (event: KeyboardEvent) {
|
||||||
|
const target = event.target as HTMLInputElement
|
||||||
|
|
||||||
|
if (target) {
|
||||||
|
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
|
||||||
|
event.preventDefault()
|
||||||
|
handleOkClick()
|
||||||
|
} else if (event.key === 'Enter') {
|
||||||
|
// ignore customized editable divs to not interrupt multiline behavior
|
||||||
|
if (!target.isContentEditable) {
|
||||||
|
event.preventDefault()
|
||||||
|
focusManager?.next(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleOkClick () {
|
||||||
|
if (canSave) {
|
||||||
|
if (okProcessing) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
okProcessing = true
|
||||||
|
const r = okAction()
|
||||||
|
if (r instanceof Promise) {
|
||||||
|
r.then(() => {
|
||||||
|
okProcessing = false
|
||||||
|
dispatch('close')
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
okProcessing = false
|
||||||
|
dispatch('close')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
||||||
@ -59,7 +98,7 @@
|
|||||||
id={label}
|
id={label}
|
||||||
class="antiCard {$deviceInfo.isMobile ? 'mobile' : 'dialog'} {width}"
|
class="antiCard {$deviceInfo.isMobile ? 'mobile' : 'dialog'} {width}"
|
||||||
class:full={fullSize}
|
class:full={fullSize}
|
||||||
on:keydown
|
on:keydown={handleKeyDown}
|
||||||
on:submit|preventDefault={() => {}}
|
on:submit|preventDefault={() => {}}
|
||||||
use:resizeObserver={() => {
|
use:resizeObserver={() => {
|
||||||
dispatch('changeContent')
|
dispatch('changeContent')
|
||||||
@ -159,22 +198,7 @@
|
|||||||
label={okLabel}
|
label={okLabel}
|
||||||
kind={'primary'}
|
kind={'primary'}
|
||||||
size={'large'}
|
size={'large'}
|
||||||
on:click={() => {
|
on:click={handleOkClick}
|
||||||
if (okProcessing) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
okProcessing = true
|
|
||||||
const r = okAction()
|
|
||||||
if (r instanceof Promise) {
|
|
||||||
r.then(() => {
|
|
||||||
okProcessing = false
|
|
||||||
dispatch('close')
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
okProcessing = false
|
|
||||||
dispatch('close')
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="buttons-group small-gap text-sm">
|
<div class="buttons-group small-gap text-sm">
|
||||||
|
@ -132,7 +132,7 @@
|
|||||||
focusManager?.setFocus(idx)
|
focusManager?.setFocus(idx)
|
||||||
}
|
}
|
||||||
$: if (input) {
|
$: if (input) {
|
||||||
input.addEventListener('focus', updateFocus, { once: true })
|
input.addEventListener('focus', updateFocus)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function focus (): void {
|
export function focus (): void {
|
||||||
|
Loading…
Reference in New Issue
Block a user