-
Notifications
You must be signed in to change notification settings - Fork 290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow touch scroll to be default prevented by making the handlers passive #423
Conversation
examples/TouchScrollExample.js
Outdated
@@ -25,7 +25,7 @@ class TouchScrollExample extends React.Component { | |||
// scrolling of parent containers of FDT. This style is a work around to fix this. By applying 'none' to | |||
// touch-action, we are disabling touch events from propagating. | |||
const tableParentStyle = { | |||
'touch-action': 'none' | |||
'touchAction': 'none' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.. It worked anyway, so I guess React was being lenient.
src/ReactTouchHandler.js
Outdated
@@ -148,6 +148,7 @@ class ReactTouchHandler { | |||
} | |||
|
|||
onTouchMove(/*object*/ event) { | |||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the delta is zero, preventDefault
wasn't being called. This is why the parent container / page get's scrolled
when the table is at any start/end scroll position
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this lead to the issue where you can't scroll the parent page with your pointer over the grid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wcjordan , Yes exactly. My reasoning was that I wouldn't want to scroll any container if the cursor is on the table. But now I agree, that it's better to have a FF control this instead (#419 (comment)). Will add
src/ReactTouchHandler.js
Outdated
@@ -148,6 +148,7 @@ class ReactTouchHandler { | |||
} | |||
|
|||
onTouchMove(/*object*/ event) { | |||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this lead to the issue where you can't scroll the parent page with your pointer over the grid?
@@ -64,6 +64,8 @@ class ReactWheelHandler { | |||
} | |||
|
|||
onWheel(/*object*/ event) { | |||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this lead to the issue where you can't scroll the parent page with your pointer over the grid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, same as above.
@@ -456,11 +456,18 @@ class FixedDataTable extends React.Component { | |||
} | |||
|
|||
componentWillUnmount() { | |||
// TODO (pradeep): Remove these and pass to our table component directly after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the related issue if you want to reference it:
facebook/react#6436
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, will put.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a FF control the behavior. And default it so that scroll handlers are only default prevented when scroll offsets have changed (existing behavior)
@@ -456,11 +456,18 @@ class FixedDataTable extends React.Component { | |||
} | |||
|
|||
componentWillUnmount() { | |||
// TODO (pradeep): Remove these and pass to our table component directly after |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, will put.
src/ReactTouchHandler.js
Outdated
@@ -148,6 +148,7 @@ class ReactTouchHandler { | |||
} | |||
|
|||
onTouchMove(/*object*/ event) { | |||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wcjordan , Yes exactly. My reasoning was that I wouldn't want to scroll any container if the cursor is on the table. But now I agree, that it's better to have a FF control this instead (#419 (comment)). Will add
@@ -64,6 +64,8 @@ class ReactWheelHandler { | |||
} | |||
|
|||
onWheel(/*object*/ event) { | |||
event.preventDefault(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, same as above.
@wcjordan , added a flag to work around the behavior seen in #419. |
/> | ||
</Table> | ||
</div> | ||
<Table |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just removed the wrapper div since the parent element and style is no longer needed
* doesn't lead to a change in scroll offsets, which is preferable if you like | ||
* the page/container to scroll up when the table is already scrolled up max. | ||
*/ | ||
stopScrollDefaultHandling: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the prop name and description fine?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the term "default handled" to "bubbled to the browser default handler"?
I'd also change "disabled/unspecified" to "disabled (default when unspecified)"
Otherwise looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
* doesn't lead to a change in scroll offsets, which is preferable if you like | ||
* the page/container to scroll up when the table is already scrolled up max. | ||
*/ | ||
stopScrollDefaultHandling: PropTypes.bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you change the term "default handled" to "bubbled to the browser default handler"?
I'd also change "disabled/unspecified" to "disabled (default when unspecified)"
Otherwise looks good.
src/ReactTouchHandler.js
Outdated
@@ -78,7 +79,15 @@ class ReactTouchHandler { | |||
emptyFunction.thatReturnsFalse; | |||
} | |||
|
|||
// Can we just make this a boolean flag instead? | |||
if (typeof preventDefault !== 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, let's not support passing a function. It doesn't take args, so I can't imagine what they would be using to decide...
Description
Made the touch handler passive through
addEventListener
(similar to #422)Moved
event.preventDefault
calls to the top so that they are always executed.Motivation and Context
Allows event to be default prevented, and thus (hopefully) fixes
How Has This Been Tested?
Tested on our touch scroll example using chrome device tools. With the fix the page doesn't get scrolled, even when the table is already scrolled to the start/end
Types of changes
Checklist: