Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 671d72d

Browse files
joyzhongcopybara-github
authored andcommitted
fix(slider): Use mouse/touch events on iOS, to work around pointer events bug.
Fixes #6715 PiperOrigin-RevId: 349586007
1 parent 7fda867 commit 671d72d

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

packages/mdc-slider/foundation.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ const HAS_WINDOW = typeof window !== 'undefined';
3939
* - Updating DOM after slider property updates (e.g. min, max).
4040
*/
4141
export class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
42-
static SUPPORTS_POINTER_EVENTS = HAS_WINDOW && Boolean(window.PointerEvent);
42+
static SUPPORTS_POINTER_EVENTS = HAS_WINDOW && Boolean(window.PointerEvent) &&
43+
// #setPointerCapture is buggy on iOS, so we can't use pointer events
44+
// until the following bug is fixed:
45+
// https://bugs.webkit.org/show_bug.cgi?id=220196
46+
!isIOS();
4347

4448
// Whether the initial styles (to position the thumb, before component
4549
// initialization) have been removed.
@@ -1060,3 +1064,14 @@ export class MDCSliderFoundation extends MDCFoundation<MDCSliderAdapter> {
10601064
this.adapter.deregisterEventHandler('pointermove', this.moveListener);
10611065
}
10621066
}
1067+
1068+
function isIOS() {
1069+
// Source:
1070+
// https://stackoverflow.com/questions/9038625/detect-if-device-is-ios
1071+
return [
1072+
'iPad Simulator', 'iPhone Simulator', 'iPod Simulator', 'iPad', 'iPhone',
1073+
'iPod'
1074+
].includes(navigator.platform)
1075+
// iPad on iOS 13 detection
1076+
|| (navigator.userAgent.includes('Mac') && 'ontouchend' in document);
1077+
}

0 commit comments

Comments
 (0)