Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): MkRangeのタッチ操作時にtooltipが複数重なって表示されないように #14548

Merged
merged 7 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- Enhance: ScratchpadにUIインスペクターを追加
- Fix: サーバーメトリクスが2つ以上あるとリロード直後の表示がおかしくなる問題を修正
- Fix: 月の違う同じ日はセパレータが表示されないのを修正
- Fix: タッチ画面でレンジスライダーを操作するとツールチップが複数表示される問題を修正
(Cherry-picked from https://github.com/taiyme/misskey/pull/265)
- Fix: 縦横比が極端なカスタム絵文字を表示する際にレイアウトが崩れる箇所があるのを修正
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/725)
- Fix: 設定変更時のリロード確認ダイアログが複数個表示されることがある問題を修正
Expand Down
54 changes: 45 additions & 9 deletions packages/frontend/src/components/MkRange.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SPDX-License-Identifier: AGPL-3.0-only

<template>
<div class="timctyfi" :class="{ disabled, easing }">
<div class="label"><slot name="label"></slot></div>
<div class="label">
<slot name="label"></slot>
</div>
<div v-adaptive-border class="body">
<div ref="containerEl" class="container">
<div class="track">
Expand All @@ -14,15 +16,25 @@ SPDX-License-Identifier: AGPL-3.0-only
<div v-if="steps && showTicks" class="ticks">
<div v-for="i in (steps + 1)" class="tick" :style="{ left: (((i - 1) / steps) * 100) + '%' }"></div>
</div>
<div ref="thumbEl" v-tooltip="textConverter(finalValue)" class="thumb" :style="{ left: thumbPosition + 'px' }" @mousedown="onMousedown" @touchstart="onMousedown"></div>
<div
ref="thumbEl"
class="thumb"
:style="{ left: thumbPosition + 'px' }"
@mouseenter.passive="onMouseenter"
@mousedown="onMousedown"
@touchstart="onMousedown"
></div>
</div>
</div>
<div class="caption"><slot name="caption"></slot></div>
<div class="caption">
<slot name="caption"></slot>
</div>
</div>
</template>

<script lang="ts" setup>
import { computed, defineAsyncComponent, onMounted, onUnmounted, ref, watch, shallowRef } from 'vue';
import { computed, defineAsyncComponent, onMounted, onUnmounted, ref, shallowRef, watch } from 'vue';
import { isTouchUsing } from '@/scripts/touch.js';
import * as os from '@/os.js';

const props = withDefaults(defineProps<{
Expand Down Expand Up @@ -101,12 +113,36 @@ const steps = computed(() => {
}
});

const tooltipForDragShowing = ref(false);
const tooltipForHoverShowing = ref(false);

function onMouseenter() {
if (isTouchUsing) return;

tooltipForHoverShowing.value = true;

const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkTooltip.vue')), {
showing: computed(() => tooltipForHoverShowing.value && !tooltipForDragShowing.value),
text: computed(() => {
return props.textConverter(finalValue.value);
}),
targetElement: thumbEl,
}, {
closed: () => dispose(),
});

thumbEl.value!.addEventListener('mouseleave', () => {
tooltipForHoverShowing.value = false;
}, { once: true, passive: true });
}

function onMousedown(ev: MouseEvent | TouchEvent) {
ev.preventDefault();

const tooltipShowing = ref(true);
tooltipForDragShowing.value = true;

const { dispose } = os.popup(defineAsyncComponent(() => import('@/components/MkTooltip.vue')), {
showing: tooltipShowing,
showing: tooltipForDragShowing,
text: computed(() => {
return props.textConverter(finalValue.value);
}),
Expand Down Expand Up @@ -137,7 +173,7 @@ function onMousedown(ev: MouseEvent | TouchEvent) {

const onMouseup = () => {
document.head.removeChild(style);
tooltipShowing.value = false;
tooltipForDragShowing.value = false;
window.removeEventListener('mousemove', onDrag);
window.removeEventListener('touchmove', onDrag);
window.removeEventListener('mouseup', onMouseup);
Expand Down Expand Up @@ -261,12 +297,12 @@ function onMousedown(ev: MouseEvent | TouchEvent) {
> .container {
> .track {
> .highlight {
transition: width 0.2s cubic-bezier(0,0,0,1);
transition: width 0.2s cubic-bezier(0, 0, 0, 1);
}
}

> .thumb {
transition: left 0.2s cubic-bezier(0,0,0,1);
transition: left 0.2s cubic-bezier(0, 0, 0, 1);
}
}
}
Expand Down
Loading