Skip to content
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 embedding impetus-enabled elements into other impetus-enabled elements #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 12 additions & 0 deletions dist/impetus.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,18 @@
* @param {Object} ev Normalized event
*/
function onDown(ev) {
// This allows embedding impetus-enabled elements into other impetus-enabled elements (such as a scrollable div
// within another) by making any ancestor impetus ignore the down event. Normally we would use stopPropagation to
// prevent the event from bubbling up to the ancestor impetus (which does work as expected in raw HTML). However,
// this approach does not work in React because React implements its own event system, which causes all sorts of
// issues with non-React stopPropagation as native DOM events propagate before react events are triggered and
// propagate. Instead, we simply tag the event as handled. Ancestor impetus instances then ignore the event if
// it's been marked as handled.
// https://dlinau.wordpress.com/2015/09/16/avoid-mixing-reacts-event-system-with-native-dom-event-handling/
// https://github.com/facebook/react/issues/8693
if (ev.handledByImpetus) return;
ev.handledByImpetus = true;

var event = normalizeEvent(ev);
if (!pointerActive && !paused) {
pointerActive = true;
Expand Down
2 changes: 1 addition & 1 deletion dist/impetus.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/impetus.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/Impetus.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ export default class Impetus {
* @param {Object} ev Normalized event
*/
function onDown(ev) {
// This allows embedding impetus-enabled elements into other impetus-enabled elements (such as a scrollable div
// within another) by making any ancestor impetus ignore the down event. Normally we would use stopPropagation to
// prevent the event from bubbling up to the ancestor impetus (which does work as expected in raw HTML). However,
// this approach does not work in React because React implements its own event system, which causes all sorts of
// issues with non-React stopPropagation as native DOM events propagate before react events are triggered and
// propagate. Instead, we simply tag the event as handled. Ancestor impetus instances then ignore the event if
// it's been marked as handled.
// https://dlinau.wordpress.com/2015/09/16/avoid-mixing-reacts-event-system-with-native-dom-event-handling/
// https://github.com/facebook/react/issues/8693
if (ev.handledByImpetus) return;
ev.handledByImpetus = true;

var event = normalizeEvent(ev);
if (!pointerActive && !paused) {
pointerActive = true;
Expand Down