Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
import { useFocusRegionWatcher } from 'common/hooks/focus';
import { useCloseChakraTooltipsOnDragFix } from 'common/hooks/useCloseChakraTooltipsOnDragFix';
import { useGlobalHotkeys } from 'common/hooks/useGlobalHotkeys';
import { useTouchDeviceClass } from 'common/hooks/useTouchDeviceClass';
import { useDndMonitor } from 'features/dnd/useDndMonitor';
import { useDynamicPromptsWatcher } from 'features/dynamicPrompts/hooks/useDynamicPromptsWatcher';
import { useStarterModelsToast } from 'features/modelManagerV2/hooks/useStarterModelsToast';
Expand Down Expand Up @@ -42,6 +43,7 @@ export const GlobalHookIsolator = memo(() => {
useGetOpenAPISchemaQuery();
useSyncLoggingConfig();
useCloseChakraTooltipsOnDragFix();
useTouchDeviceClass();
useDndMonitor();
useSyncNodeErrors();
useSyncLangDirection();
Expand Down
10 changes: 4 additions & 6 deletions invokeai/frontend/web/src/app/components/touchDevice.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* Hide tooltips on touch devices where hover gets "stuck" */
@media (hover: none) {
[role='tooltip'] {
visibility: hidden !important;
opacity: 0 !important;
}
/* Hide tooltips after touch input, where hover can get stuck. */
.invokeai-touch-device [role='tooltip'] {
visibility: hidden !important;
opacity: 0 !important;
}
15 changes: 15 additions & 0 deletions invokeai/frontend/web/src/app/components/touchDevice.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { readFileSync } from 'node:fs';

import { describe, expect, it } from 'vitest';

const css = readFileSync(new URL('./touchDevice.css', import.meta.url), 'utf8');

describe('touchDevice.css', () => {
it('hides tooltips only after touch input has been detected', () => {
expect(css).toMatch(/\.invokeai-touch-device\s+\[role='tooltip'\]\s*{/);
});

it('does not force all tooltips invisible', () => {
expect(css).not.toMatch(/@media\s*\([^)]*hover[^)]*\)/);
});
});
23 changes: 23 additions & 0 deletions invokeai/frontend/web/src/common/hooks/useTouchDeviceClass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useEffect } from 'react';

const TOUCH_DEVICE_CLASS = 'invokeai-touch-device';

export const useTouchDeviceClass = () => {
useEffect(() => {
const onPointerInput = (e: PointerEvent) => {
if (e.pointerType === 'touch') {
document.documentElement.classList.add(TOUCH_DEVICE_CLASS);
} else if (e.pointerType === 'mouse') {
document.documentElement.classList.remove(TOUCH_DEVICE_CLASS);
}
};

window.addEventListener('pointerdown', onPointerInput, { passive: true });
window.addEventListener('pointermove', onPointerInput, { passive: true });

return () => {
window.removeEventListener('pointerdown', onPointerInput);
window.removeEventListener('pointermove', onPointerInput);
};
}, []);
};
Loading