fix(client): タッチ機能付きディスプレイを使っていてマウス操作をしている場合に一部機能が動作しない問題を修正
This commit is contained in:
@ -1 +0,0 @@
|
||||
export const isDeviceTouch = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0;
|
19
packages/client/src/scripts/touch.ts
Normal file
19
packages/client/src/scripts/touch.ts
Normal file
@ -0,0 +1,19 @@
|
||||
const isTouchSupported = 'maxTouchPoints' in navigator && navigator.maxTouchPoints > 0;
|
||||
|
||||
export let isTouchUsing = false;
|
||||
|
||||
export let isScreenTouching = false;
|
||||
|
||||
if (isTouchSupported) {
|
||||
window.addEventListener('touchstart', () => {
|
||||
// maxTouchPointsなどでの判定だけだと、「タッチ機能付きディスプレイを使っているがマウスでしか操作しない」場合にも
|
||||
// タッチで使っていると判定されてしまうため、実際に一度でもタッチされたらtrueにする
|
||||
isTouchUsing = true;
|
||||
|
||||
isScreenTouching = true;
|
||||
}, { passive: true });
|
||||
|
||||
window.addEventListener('touchend', () => {
|
||||
isScreenTouching = false;
|
||||
}, { passive: true });
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
import { isScreenTouching } from '@/os';
|
||||
import { Ref, ref } from 'vue';
|
||||
import { isDeviceTouch } from './is-device-touch';
|
||||
import { isScreenTouching, isTouchUsing } from './touch';
|
||||
|
||||
export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
|
||||
let isHovering = false;
|
||||
@ -14,7 +13,7 @@ export function useTooltip(onShow: (showing: Ref<boolean>) => void) {
|
||||
|
||||
// iOS(Androidも?)では、要素をタップした直後に(おせっかいで)mouseoverイベントを発火させたりするため、その対策
|
||||
// これが無いと、画面に触れてないのにツールチップが出たりしてしまう
|
||||
if (isDeviceTouch && !isScreenTouching) return;
|
||||
if (isTouchUsing && !isScreenTouching) return;
|
||||
|
||||
const showing = ref(true);
|
||||
onShow(showing);
|
||||
|
Reference in New Issue
Block a user