Skip to content

Commit 36d99b4

Browse files
committed
feat: possibility to disable active state
1 parent 0ba61df commit 36d99b4

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

README.MD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const cursor = new MouseFollower({
113113
| `hiddenState` | `string` | Hidden class name state. |
114114
| `textState` | `string` | Text class name state. |
115115
| `iconState` | `string` | Icon class name state. |
116-
| `activeState` | `string` | Active (mousedown) class name state. |
116+
| `activeState` | `string` | `null` | Active (mousedown) class name state. Set `false` to disable. |
117117
| `mediaState` | `string` | Media (image/video) class name state. |
118118
| `visible` | `boolean` | Is cursor visible by default. |
119119
| `visibleOnState` | `boolean` | Automatically show/hide cursor when state added. Can be useful when implementing a hidden cursor follower. |

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default class MouseFollower {
3434
* @param {string} options.hiddenState Hidden state name.
3535
* @param {string} options.textState Text state name.
3636
* @param {string} options.iconState Icon state name.
37-
* @param {string} options.activeState Active (mousedown) state name.
37+
* @param {string|null} options.activeState Active (mousedown) state name. Set false to disable.
3838
* @param {string} options.mediaState Media (image/video) state name.
3939
* @param {object} options.stateDetection State detection rules.
4040
* @param {boolean} options.visible Is cursor visible by default.
@@ -232,8 +232,10 @@ export default class MouseFollower {
232232
if (this.options.visible) {
233233
this.container.addEventListener('mouseenter', this.event.mouseenter, {passive: true});
234234
}
235-
this.container.addEventListener('mousedown', this.event.mousedown, {passive: true});
236-
this.container.addEventListener('mouseup', this.event.mouseup, {passive: true});
235+
if (this.options.activeState) {
236+
this.container.addEventListener('mousedown', this.event.mousedown, {passive: true});
237+
this.container.addEventListener('mouseup', this.event.mouseup, {passive: true});
238+
}
237239
this.container.addEventListener('mousemove', this.event.mousemove, {passive: true});
238240
if (this.options.visible) {
239241
this.container.addEventListener('mousemove', this.event.mousemoveOnce, {

0 commit comments

Comments
 (0)