Skip to content

Commit

Permalink
feat: prevent click bubbling #89
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Aug 2, 2022
1 parent 30575a1 commit 6538396
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/selecto/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "selecto",
"version": "1.17.0",
"version": "1.18.0",
"description": "Selecto.js is a component that allows you to select elements in the drag area using the mouse or touch.",
"main": "./dist/selecto.cjs.js",
"module": "./dist/selecto.esm.js",
Expand Down
12 changes: 10 additions & 2 deletions packages/selecto/src/SelectoManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,13 @@ class Selecto extends EventEmitter<SelectoEvents> {

const target = this.target;

const { dragContainer, checkInput, preventDefault } = this.options;
const {
dragContainer,
checkInput,
preventDefault,
preventClickEventOnDragStart,
preventClickEventOnDrag,
} = this.options;
this.dragContainer =
typeof dragContainer === "string"
? [].slice.call(document.querySelectorAll(dragContainer))
Expand All @@ -367,6 +373,8 @@ class Selecto extends EventEmitter<SelectoEvents> {
container: window,
checkInput,
preventDefault,
preventClickEventOnDragStart,
preventClickEventOnDrag,
}).on({
dragStart: this._onDragStart,
drag: this._onDrag,
Expand Down Expand Up @@ -968,10 +976,10 @@ class Selecto extends EventEmitter<SelectoEvents> {
if (inputEvent && !e.isClick) {
this.emit("dragEnd", {
isDouble: !!e.isDouble,
isClick: !!e.isClick,
isDrag: false,
isSelect: selectFlag,
...e,
isClick: !!e.isClick,
rect,
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/selecto/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const OPTIONS = [
// ignore target, container,
"dragContainer",
"cspNonce",
"preventClickEventOnDrag",
"preventClickEventOnDragStart",
...PROPERTIES,
] as const;

Expand Down Expand Up @@ -73,6 +75,8 @@ export const OPTION_TYPES: { [key in keyof SelectoOptions]: any } = {
dragCondition: Function,
clickBySelectEnd: Boolean,
continueSelectWithoutDeselect: Boolean,
preventClickEventOnDragStart: Boolean,
preventClickEventOnDrag: Boolean,
};

/**
Expand Down
12 changes: 12 additions & 0 deletions packages/selecto/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ export interface SelectoOptions {
* @default null
*/
dragCondition: ((e: OnParentDragStart) => boolean) | null;
/**
* Prevent click event on drag. (mousemove, touchmove)
* @default false
*/
preventClickEventOnDrag?: boolean;
/**
* Prevent click event on dragStart. (mousedown, touchstart)
* @default false
*/
preventClickEventOnDragStart?: boolean;
/**
* Selection Element to apply for framework.
* @private
Expand Down Expand Up @@ -213,6 +223,8 @@ export interface OnDragEvent {
deltaY: number;
distX: number;
distY: number;
isMouseEvent: boolean;
isSecondaryButton: boolean;
isClick?: boolean;
isDouble?: boolean;
inputEvent: any;
Expand Down
1 change: 1 addition & 0 deletions packages/selecto/test/manual/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

<div class="hi"></div>
<script>

const selecto = new Selecto({
container: document.body,
// rootContainer: document.body,
Expand Down

0 comments on commit 6538396

Please sign in to comment.