Skip to content

Commit e7e3aeb

Browse files
committed
perf: remove chrome passive warning
1 parent fa5a6d8 commit e7e3aeb

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

components/_util/pickAttrs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const eventsName = `onCopy onCut onPaste onCompositionend onCompositionstart onC
1515
onKeypress onKeyup onFocus onBlur onChange onInput onSubmit onClick onContextmenu onDoubleclick onDblclick
1616
onDrag onDragend onDragenter onDragexit onDragleave onDragover onDragstart onDrop onMousedown
1717
onMouseenter onMouseleave onMousemove onMouseout onMouseover onMouseup onSelect onTouchcancel
18-
onTouchend onTouchmove onTouchstart onScroll onWheel onAbort onCanplay onCanplaythrough
18+
onTouchend onTouchmove onTouchstart onTouchstartPassive onTouchmovePassive onScroll onWheel onAbort onCanplay onCanplaythrough
1919
onDurationchange onEmptied onEncrypted onEnded onError onLoadeddata onLoadedmetadata
2020
onLoadstart onPause onPlay onPlaying onProgress onRatechange onSeeked onSeeking onStalled onSuspend onTimeupdate onVolumechange onWaiting onLoad onError`;
2121

components/vc-drawer/src/Drawer.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,15 @@ const Drawer = defineComponent({
439439
onKeydown: open && keyboard ? this.onKeyDown : noop,
440440
style: { ...wrapStyle, ...style },
441441
};
442+
// 跑用例用
443+
const touchEvents = {
444+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']: open
445+
? this.removeStartHandler
446+
: noop,
447+
[supportsPassive ? 'onTouchmovePassive' : 'onTouchmove']: open
448+
? this.removeMoveHandler
449+
: noop,
450+
};
442451
return (
443452
<div
444453
ref={c => {
@@ -475,8 +484,7 @@ const Drawer = defineComponent({
475484
ref={c => {
476485
this.contentDom = c;
477486
}}
478-
onTouchstart={open ? this.removeStartHandler : noop} // 跑用例用
479-
onTouchmove={open ? this.removeMoveHandler : noop} // 跑用例用
487+
{...touchEvents}
480488
>
481489
{children}
482490
</div>

components/vc-input-number/src/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import classNames from '../../_util/classNames';
66
import KeyCode from '../../_util/KeyCode';
77
import InputHandler from './InputHandler';
88
import { defineComponent } from 'vue';
9+
import supportsPassive from '../../_util/supportsPassive';
910

1011
function preventDefault(e) {
1112
e.preventDefault();
@@ -699,11 +700,13 @@ export default defineComponent({
699700
let downEvents;
700701
if (useTouch) {
701702
upEvents = {
702-
onTouchstart: editable && !upDisabledClass && this.up,
703+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']:
704+
editable && !upDisabledClass && this.up,
703705
onTouchend: this.stop,
704706
};
705707
downEvents = {
706-
onTouchstart: editable && !downDisabledClass && this.down,
708+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']:
709+
editable && !downDisabledClass && this.down,
707710
onTouchend: this.stop,
708711
};
709712
} else {

components/vc-m-feedback/src/TouchFeedback.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import warning from '../../_util/warning';
55
import BaseMixin from '../../_util/BaseMixin';
66
import { ITouchProps } from './PropTypes';
77
import { defineComponent } from 'vue';
8+
import supportsPassive from '../../_util/supportsPassive';
89

910
export default defineComponent({
1011
name: 'TouchFeedback',
@@ -76,8 +77,8 @@ export default defineComponent({
7677
const events = disabled
7778
? undefined
7879
: {
79-
onTouchstart: this.onTouchStart,
80-
onTouchmove: this.onTouchMove,
80+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']: this.onTouchStart,
81+
[supportsPassive ? 'onTouchmovePassive' : 'onTouchmove']: this.onTouchMove,
8182
onTouchend: this.onTouchEnd,
8283
onTouchcancel: this.onTouchCancel,
8384
onMousedown: this.onMouseDown,

components/vc-slick/src/inner-slider.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
import Track from './track';
2424
import Dots from './dots';
2525
import { PrevArrow, NextArrow } from './arrows';
26+
import supportsPassive from '../../_util/supportsPassive';
2627

2728
function noop() {}
2829

@@ -694,8 +695,11 @@ export default {
694695
onMousemove: this.dragging && touchMove ? this.swipeMove : noop,
695696
onMouseup: touchMove ? this.swipeEnd : noop,
696697
onMouseleave: this.dragging && touchMove ? this.swipeEnd : noop,
697-
onTouchstart: touchMove ? this.swipeStart : noop,
698-
onTouchmove: this.dragging && touchMove ? this.swipeMove : noop,
698+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']: touchMove
699+
? this.swipeStart
700+
: noop,
701+
[supportsPassive ? 'onTouchmovePassive' : 'onTouchmove']:
702+
this.dragging && touchMove ? this.swipeMove : noop,
699703
onTouchend: touchMove ? this.swipeEnd : noop,
700704
onTouchcancel: this.dragging && touchMove ? this.swipeEnd : noop,
701705
onKeydown: this.accessibility ? this.keyHandler : noop,

components/vc-slider/src/common/Marks.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import supportsPassive from '../../../_util/supportsPassive';
12
import classNames from '../../../_util/classNames';
23
import { isValidElement } from '../../../_util/props-util';
34

@@ -51,13 +52,16 @@ const Marks = (_, { attrs }) => {
5152

5253
const style = vertical ? bottomStyle : leftStyle;
5354
const markStyle = markPointIsObject ? { ...style, ...markPoint.style } : style;
55+
const touchEvents = {
56+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']: e => onClickLabel(e, point),
57+
};
5458
return (
5559
<span
5660
class={markClassName}
5761
style={markStyle}
5862
key={point}
5963
onMousedown={e => onClickLabel(e, point)}
60-
onTouchstart={e => onClickLabel(e, point)}
64+
{...touchEvents}
6165
>
6266
{markLabel}
6367
</span>

components/vc-slider/src/common/createSlider.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Marks from './Marks';
99
import Handle from '../Handle';
1010
import * as utils from '../utils';
1111
import BaseMixin from '../../../_util/BaseMixin';
12+
import supportsPassive from '../../../_util/supportsPassive';
1213

1314
function noop() {}
1415

@@ -295,13 +296,18 @@ export default function createSlider(Component) {
295296
class: `${prefixCls}-mark`,
296297
onClickLabel: disabled ? noop : this.onClickMarkLabel,
297298
};
299+
const touchEvents = {
300+
[supportsPassive ? 'onTouchstartPassive' : 'onTouchstart']: disabled
301+
? noop
302+
: this.onTouchStart,
303+
};
298304
return (
299305
<div
300306
id={id}
301307
ref={this.saveSlider}
302308
tabindex="-1"
303309
class={sliderClassName}
304-
onTouchstart={disabled ? noop : this.onTouchStart}
310+
{...touchEvents}
305311
onMousedown={disabled ? noop : this.onMouseDown}
306312
onMouseup={disabled ? noop : this.onMouseUp}
307313
onKeydown={disabled ? noop : this.onKeyDown}

0 commit comments

Comments
 (0)