Skip to content

Commit

Permalink
refactor: explicitly set and apply capture property for event bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdyman committed Aug 28, 2023
1 parent c69e950 commit ebd9078
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ReactCompareSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface UpdateInternalPositionProps {
isOffset?: boolean;
}

const EVENT_PASSIVE_PARAMS = { passive: true };
const EVENT_PASSIVE_PARAMS = { capture: false, passive: true };
const EVENT_CAPTURE_PARAMS = { capture: true, passive: false };

/** Root Comparison slider. */
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export interface ReactCompareSliderCommonProps {
/** Divider position. */
position: ReactCompareSliderPropPosition;
/**
* Shorthand CSS `transition` properties to apply to handle movement - does not need transition property.
* Shorthand CSS `transition` property to apply to handle movement. The specific CSS property
* to transition **must not** be provided.
* @example '.5s ease-in-out'
*/
transition?: string;
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ export const useEventListener = (
const eventListener: EventListener = (event) =>
savedHandler.current && savedHandler.current(event);

element.addEventListener(eventName, eventListener, handlerOptions);
element.addEventListener(eventName, eventListener, { capture: handlerOptions.capture });

return (): void => {
element.removeEventListener(eventName, eventListener, handlerOptions);
element.removeEventListener(eventName, eventListener, { capture: handlerOptions.capture });
};
}, [eventName, element, handlerOptions]);
};
Expand Down

0 comments on commit ebd9078

Please sign in to comment.