Skip to content

Commit 3f78d73

Browse files
committed
Use pointer type to toggle scroll buttons instead of only touch
1 parent 56b1267 commit 3f78d73

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/elements/emby-scroller/Scroller.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { type FC, type PropsWithChildren, useCallback, useEffect, useRef, useState } from 'react';
22
import classNames from 'classnames';
3+
import useMediaQuery from '@mui/material/useMediaQuery';
34
import useElementSize from 'hooks/useElementSize';
5+
import { FINE_POINTER_MEDIA_QUERY } from 'utils/pointer';
46
import layoutManager from '../../components/layoutManager';
57
import dom from '../../utils/dom';
68
import browser from '../../scripts/browser';
@@ -34,6 +36,7 @@ const Scroller: FC<PropsWithChildren<ScrollerProps>> = ({
3436
children
3537
}) => {
3638
const [scrollRef, size] = useElementSize();
39+
const hasFinePointer = useMediaQuery(FINE_POINTER_MEDIA_QUERY);
3740

3841
const [showControls, setShowControls] = useState(false);
3942
const [scrollState, setScrollState] = useState({
@@ -158,7 +161,7 @@ const Scroller: FC<PropsWithChildren<ScrollerProps>> = ({
158161
return;
159162
}
160163

161-
const enableScrollButtons = layoutManager.desktop && !browser.touch && isHorizontalEnabled && isScrollButtonsEnabled;
164+
const enableScrollButtons = layoutManager.desktop && hasFinePointer && isHorizontalEnabled && isScrollButtonsEnabled;
162165

163166
const options = {
164167
horizontal: isHorizontalEnabled,
@@ -195,9 +198,10 @@ const Scroller: FC<PropsWithChildren<ScrollerProps>> = ({
195198
capture: false,
196199
passive: true
197200
});
198-
setShowControls(true);
199201
}
200202

203+
setShowControls(enableScrollButtons);
204+
201205
return () => {
202206
if (scrollerFactoryRef.current) {
203207
scrollerFactoryRef.current.destroy();
@@ -211,6 +215,7 @@ const Scroller: FC<PropsWithChildren<ScrollerProps>> = ({
211215
};
212216
}, [
213217
addScrollEventListener,
218+
hasFinePointer,
214219
initCenterFocus,
215220
isAllowNativeSmoothScrollEnabled,
216221
isCenterFocusEnabled,

src/elements/emby-scroller/emby-scroller.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import layoutManager from '../../components/layoutManager';
44
import inputManager from '../../scripts/inputManager';
55
import focusManager from '../../components/focusManager';
66
import browser from '../../scripts/browser';
7+
import { hasFinePointer } from '../../utils/pointer';
78
import 'webcomponents.js/webcomponents-lite';
89
import './emby-scroller.scss';
910

@@ -116,7 +117,7 @@ ScrollerPrototype.attachedCallback = function () {
116117
}
117118

118119
const scrollFrame = this;
119-
const enableScrollButtons = layoutManager.desktop && !browser.touch && horizontal && this.getAttribute('data-scrollbuttons') !== 'false';
120+
const enableScrollButtons = layoutManager.desktop && hasFinePointer() && horizontal && this.getAttribute('data-scrollbuttons') !== 'false';
120121

121122
const options = {
122123
horizontal: horizontal,

src/utils/pointer.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Matches when the primary pointing device is precise (mouse/trackpad).
3+
* Touch-first devices report a "coarse" primary pointer even when a pointer
4+
* device is attached, making this a better signal than touch capability for
5+
* mouse-only affordances.
6+
*/
7+
export const FINE_POINTER_MEDIA_QUERY = '(pointer: fine)';
8+
9+
export const hasFinePointer = () => window.matchMedia(FINE_POINTER_MEDIA_QUERY).matches;

0 commit comments

Comments
 (0)