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

How do you make a fabricjs object "locked" (without using evented property) #6734

Closed
h-archer opened this issue Dec 17, 2020 · 2 comments
Closed

Comments

@h-archer
Copy link

h-archer commented Dec 17, 2020

How do you make a fabricjs object "locked" such that:

  1. It's not selectable (obj.selectable = false)
  2. Allow 'mousedown' event for right-click (obj.evented must be true)
  3. No hover state/event (mouse does not detect this obj on hovering or changes the cursor)
  4. Allows mouse to click objects under it (mouse can access objects through it)

I tried looking for the code that deals with the 'evented' prop but I could not find it in the source. The evented property does make the object transparent (ie. able to click through it), but removes the 'mousedown' event.

This is needed in my situation where I need to implement a context menu with lock/unlock object feature. If the object is locked, you still need to be able to right-click on it to display the context menu again so you can unlock it. Also, when locked, you need to be able to access and click objects under it.

Fabricjs 3.6.6

@h-archer h-archer changed the title How to make an object allow for clicking object under it (without using evented property) How to click through an object to select object under it (without using evented property) Dec 17, 2020
@h-archer h-archer changed the title How to click through an object to select object under it (without using evented property) How do you make a fabricjs object "locked" (without using evented property) Dec 20, 2020
@stale
Copy link

stale bot commented Jan 3, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale Issue marked as stale by the stale bot label Jan 3, 2021
@asturur
Copy link
Member

asturur commented Jan 3, 2021

There isn't such a thing for now.
The object with evented=false get removed from the findTarget function and gets excluded by everything.
What you can do is write a simple function to find the target on right click action, to run on canvas.on('mouse:down', () => {})

the function can be easily built looking at how _searchPossibleTargets works in fabricjs

@asturur asturur closed this as completed Jan 3, 2021
@stale stale bot removed the stale Issue marked as stale by the stale bot label Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants