Fix tooltips in chat (#7113)

Signed-off-by: Kristina Fefelova <kristin.fefelova@gmail.com>
This commit is contained in:
Kristina 2024-11-06 18:48:48 +04:00 committed by GitHub
parent 5b3f69a85f
commit 25445c1996
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 19 deletions

View File

@ -101,13 +101,13 @@
padding: 0.125rem 0.125rem 0.125rem 0.5rem; padding: 0.125rem 0.125rem 0.125rem 0.5rem;
height: 1.625rem; height: 1.625rem;
min-height: 1.625rem; min-height: 1.625rem;
min-width: 6rem; min-width: 4rem;
} }
&.vertical { &.vertical {
padding: 0.5rem 0.125rem 0.125rem 0.125rem; padding: 0.5rem 0.125rem 0.125rem 0.125rem;
width: 1.625rem; width: 1.625rem;
min-height: 6rem; min-height: 4rem;
writing-mode: vertical-rl; writing-mode: vertical-rl;
text-orientation: sideways; text-orientation: sideways;
} }

View File

@ -45,6 +45,7 @@
export let stickedScrollBars: boolean = false export let stickedScrollBars: boolean = false
export let thinScrollBars: boolean = false export let thinScrollBars: boolean = false
export let disableOverscroll = false export let disableOverscroll = false
export let disablePointerEventsOnScroll = false
export let onScroll: ((params: ScrollParams) => void) | undefined = undefined export let onScroll: ((params: ScrollParams) => void) | undefined = undefined
export let onResize: (() => void) | undefined = undefined export let onResize: (() => void) | undefined = undefined
@ -72,7 +73,9 @@
let divHScroll: HTMLElement let divHScroll: HTMLElement
let divBar: HTMLElement let divBar: HTMLElement
let divBarH: HTMLElement let divBarH: HTMLElement
let isScrolling: 'vertical' | 'horizontal' | false = false let isScrollingByBar: 'vertical' | 'horizontal' | false = false
let isScrolling: boolean = false
let scrollTimer: any = 0
let dXY: number let dXY: number
let belowContent: number | undefined = undefined let belowContent: number | undefined = undefined
let beforeContent: number | undefined = undefined let beforeContent: number | undefined = undefined
@ -177,14 +180,15 @@
const handleScroll = (event: PointerEvent): void => { const handleScroll = (event: PointerEvent): void => {
scrolling = false scrolling = false
if ( if (
(divBar == null && isScrolling === 'vertical') || (divBar == null && isScrollingByBar === 'vertical') ||
(divBarH == null && isScrolling === 'horizontal') || (divBarH == null && isScrollingByBar === 'horizontal') ||
divScroll == null divScroll == null
) { ) {
return return
} }
const rectScroll = divScroll.getBoundingClientRect() const rectScroll = divScroll.getBoundingClientRect()
if (isScrolling === 'vertical') { if (isScrollingByBar === 'vertical') {
let Y = Math.round(event.clientY) - dXY let Y = Math.round(event.clientY) - dXY
if (Y < rectScroll.top + shiftTop + 2) Y = rectScroll.top + shiftTop + 2 if (Y < rectScroll.top + shiftTop + 2) Y = rectScroll.top + shiftTop + 2
if (Y > rectScroll.bottom - divBar.clientHeight - shiftBottom - 2) { if (Y > rectScroll.bottom - divBar.clientHeight - shiftBottom - 2) {
@ -200,7 +204,7 @@
} else { } else {
divScroll.scrollTop = (divScroll.scrollHeight - divScroll.clientHeight) * procBar divScroll.scrollTop = (divScroll.scrollHeight - divScroll.clientHeight) * procBar
} }
} else if (isScrolling === 'horizontal') { } else if (isScrollingByBar === 'horizontal') {
let X = Math.round(event.clientX) - dXY let X = Math.round(event.clientX) - dXY
if (X < rectScroll.left + 2 + shiftLeft) X = rectScroll.left + 2 + shiftLeft if (X < rectScroll.left + 2 + shiftLeft) X = rectScroll.left + 2 + shiftLeft
if (X > rectScroll.right - divBarH.clientWidth - (mask !== 'none' ? 12 : 2) - shiftRight) { if (X > rectScroll.right - divBarH.clientWidth - (mask !== 'none' ? 12 : 2) - shiftRight) {
@ -219,7 +223,7 @@
document.body.style.userSelect = 'auto' document.body.style.userSelect = 'auto'
document.body.style.webkitUserSelect = 'auto' document.body.style.webkitUserSelect = 'auto'
document.removeEventListener('pointerup', onScrollEnd) document.removeEventListener('pointerup', onScrollEnd)
isScrolling = false isScrollingByBar = false
} }
const onScrollStart = (event: PointerEvent, direction: 'vertical' | 'horizontal'): void => { const onScrollStart = (event: PointerEvent, direction: 'vertical' | 'horizontal'): void => {
if (divScroll == null) return if (divScroll == null) return
@ -229,7 +233,7 @@
document.addEventListener('pointermove', handleScroll) document.addEventListener('pointermove', handleScroll)
document.body.style.userSelect = 'none' document.body.style.userSelect = 'none'
document.body.style.webkitUserSelect = 'none' document.body.style.webkitUserSelect = 'none'
isScrolling = direction isScrollingByBar = direction
} }
const renderFade = () => { const renderFade = () => {
@ -298,10 +302,10 @@
renderFade() renderFade()
} }
if (!isScrolling) { if (!isScrollingByBar) {
checkBar() checkBar()
} }
if (!isScrolling && horizontal) { if (!isScrollingByBar && horizontal) {
checkBarH() checkBarH()
} }
} }
@ -486,7 +490,7 @@
(divBar == null && !horizontal) || (divBar == null && !horizontal) ||
(divBarH == null && horizontal) || (divBarH == null && horizontal) ||
divScroll == null || divScroll == null ||
isScrolling !== false isScrollingByBar !== false
) { ) {
return return
} }
@ -574,6 +578,11 @@
) { ) {
closeTooltip() closeTooltip()
} }
clearTimeout(scrollTimer)
isScrolling = true
scrollTimer = setTimeout(() => {
isScrolling = false
}, 300)
}} }}
> >
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
@ -589,6 +598,7 @@
: 'row'} : 'row'}
style:height={contentDirection === 'vertical-reverse' ? 'max-content' : noStretch ? 'auto' : '100%'} style:height={contentDirection === 'vertical-reverse' ? 'max-content' : noStretch ? 'auto' : '100%'}
style:align-items={align} style:align-items={align}
class:disableEvents={isScrolling && disablePointerEventsOnScroll}
use:resizeObserver={() => { use:resizeObserver={() => {
checkAutoScroll() checkAutoScroll()
checkFade() checkFade()
@ -655,7 +665,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="track" class="track"
class:hovered={isScrolling === 'vertical'} class:hovered={isScrollingByBar === 'vertical'}
on:click|stopPropagation={(ev) => { on:click|stopPropagation={(ev) => {
clickOnTrack(ev) clickOnTrack(ev)
}} }}
@ -663,7 +673,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="bar" class="bar"
class:hovered={isScrolling === 'vertical'} class:hovered={isScrollingByBar === 'vertical'}
class:reverse={scrollDirection === 'vertical-reverse'} class:reverse={scrollDirection === 'vertical-reverse'}
bind:this={divBar} bind:this={divBar}
on:pointerdown|stopPropagation={(ev) => { on:pointerdown|stopPropagation={(ev) => {
@ -677,7 +687,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="track-horizontal" class="track-horizontal"
class:hovered={isScrolling === 'horizontal'} class:hovered={isScrollingByBar === 'horizontal'}
on:click|stopPropagation={(ev) => { on:click|stopPropagation={(ev) => {
clickOnTrack(ev, true) clickOnTrack(ev, true)
}} }}
@ -685,7 +695,7 @@
<!-- svelte-ignore a11y-no-static-element-interactions --> <!-- svelte-ignore a11y-no-static-element-interactions -->
<div <div
class="bar-horizontal" class="bar-horizontal"
class:hovered={isScrolling === 'horizontal'} class:hovered={isScrollingByBar === 'horizontal'}
bind:this={divBarH} bind:this={divBarH}
on:pointerdown|stopPropagation={(ev) => { on:pointerdown|stopPropagation={(ev) => {
onScrollStart(ev, 'horizontal') onScrollStart(ev, 'horizontal')
@ -1026,4 +1036,8 @@
height: 6px; height: 6px;
} }
} }
.disableEvents {
pointer-events: none !important;
}
</style> </style>

View File

@ -36,7 +36,7 @@ export function tooltip (node: HTMLElement, options?: LabelAndProps): any {
const show = (): void => { const show = (): void => {
const shown = !!(storedValue.label !== undefined || storedValue.component !== undefined) const shown = !!(storedValue.label !== undefined || storedValue.component !== undefined)
if (!shown) { if (!shown) {
if (opt?.kind !== 'submenu') { if (opt?.kind !== 'submenu' || opt.timeout !== undefined) {
clearTimeout(toHandler) clearTimeout(toHandler)
toHandler = setTimeout(() => { toHandler = setTimeout(() => {
showTooltip( showTooltip(
@ -50,7 +50,7 @@ export function tooltip (node: HTMLElement, options?: LabelAndProps): any {
opt.kind, opt.kind,
opt.keys opt.keys
) )
}, 10) }, opt.timeout ?? 10)
} else { } else {
showTooltip( showTooltip(
opt.label, opt.label,

View File

@ -304,6 +304,7 @@ export interface LabelAndProps {
onUpdate?: (result: any) => void onUpdate?: (result: any) => void
kind?: 'tooltip' | 'submenu' | 'popup' kind?: 'tooltip' | 'submenu' | 'popup'
keys?: string[] keys?: string[]
timeout?: number
} }
export interface ListItem { export interface ListItem {

View File

@ -36,6 +36,7 @@
noStretch noStretch
bottomStart bottomStart
disableOverscroll disableOverscroll
disablePointerEventsOnScroll
{onScroll} {onScroll}
{onResize} {onResize}
> >

View File

@ -36,7 +36,8 @@
} }
return { return {
component: EmployeePreviewPopup, component: EmployeePreviewPopup,
props: { employeeId: value._id } props: { employeeId: value._id },
timeout: 300
} }
} }
</script> </script>