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

Deselect single element on click or touch #91

Closed
LaundroMat opened this issue Jan 4, 2021 · 2 comments
Closed

Deselect single element on click or touch #91

LaundroMat opened this issue Jan 4, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@LaundroMat
Copy link

LaundroMat commented Jan 4, 2021

I'm using 2.0.0beta4

I would like to be able to deselect a single element on click or touch. This is my current config:

      this.selection = new SelectionArea({
        class: "selection-area",
        container: 'body',
        overlap: 'keep',
        singleTap: {
          // Enable single-click selection (Also disables range-selection via shift + ctrl).
          allow: true,
          // 'native' (element was mouse-event target) or 'touch' (element visually touched).
          intersect: 'touch'
        },
        selectables: "[data-box-id='" + self.box.id + "']",
        startareas: [`.cell-matrix-${self.box.id}`],
        boundaries: [`.cell-matrix-${self.box.id}`]
      })
        .on("start", ({ event: evt, store: { changed: { added, removed } } }) => {
          if (!(added.length || removed.length) && evt.type == 'mouseup') {
            // TODO: same thing for touch
            if (this.selection.getSelection().includes(evt.target)) {
              console.debug('Deselecting cell ', evt.target)
              this.selection.deselect(evt.target, true)
              this.selection.resolveSelectables()
            }
          }
        })
        .on("move", ({ store: { changed: { added, removed } } }) => {
          // Add a custom class to the elements that were selected.
          for (const el of added) {
            el.classList.add("selected");
            // this.selectedCells.push(this.convertMatrixIndexToArrayIndex(el.dataset.index))
            // this.selectedCells = uniq(this.selectedCells)
          }

          // Remove the class from elements that where removed
          // since the last selection
          for (const el of removed) {
            el.classList.remove("selected");
          }
        })
        .on("stop", () => {
          this.selection.keepSelection();
          console.debug(this.selection.getSelection())
        })

(I'm using this inside a Vue.js created function, hence the this.selection.)

The element is added on click, but it is not removed from .getSelection() when clicking on it again (although the "Deselecting cell" message appears in my console log).

@simonwep
Copy link
Owner

simonwep commented Jan 4, 2021

I see what's happening, this is indeed an issue but please stick to the Issue Template the next time. Create a JSFiddle and describe what you've done as detailed as possible and break your issue down to a minimum. This will help me to resolve it as fast as possible.
The next time your issue will be closed without further notice.

@simonwep simonwep added the bug Something isn't working label Jan 4, 2021
@simonwep
Copy link
Owner

simonwep commented Jan 4, 2021

Fixed in f71a2c9, available in 2.0.0-beta.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants