ngx-drag-to-select icon indicating copy to clipboard operation
ngx-drag-to-select copied to clipboard

[Question] Selecting interactive elements

Open andrzejkala opened this issue 5 years ago • 5 comments

Is there an option/param to disable the propagation of the click event while selecting interactive elements while the option [selectWithShortcut] is set to true?

e.g. when in "select mode" (holding down the meta key) the openDocument() event would never be fired (just the element would be selected.

<dts-select-container 
  [(selectedItems)]="selected"
  [selectWithShortcut]="true"
>
   <div class="col-4" *ngFor="let document of group.groupItems">
        <div class="card mt-3" 
          [dtsSelectItem]="document"
          (click)="openDocument(document)"
        >
          {{ document.name }}
        </div>
    </div>
</dts-select-container>

I can detect the meta key on my side and just enable/disable the openDocument() functionality, but maybe there's some simple "out of the box" way that I'm not seeing?

andrzejkala avatar Jan 31 '20 07:01 andrzejkala

Hey there! Thanks for opening this issue 🙏

That's a really good point you're bringing up there, and it totally makes sense in your use case to stop the event propagation if selectWithShortcut is enabled. However, I am not sure if this should be the default. What I can imagine though is maybe an option to disable the event propagation on the dtsSelectItem for when one of the meta keys is pressed? Would that make sense? Or do you have some solution in mind that would help you and not break others?

I'd love to bake this somehow into the library because I think this is a pretty common cause, but again, it shouldn't be the default because then we would break people.

And to answer your, no there is currently no other way, and your solution of listening for the meta key is currently the right way to achieve what you wanted to do.

Another thing is that we could add an event listener for the meta key on the container itself? So that people at least don't have to add this event themselves and they can disable for instance the click when the lib fires the metaKeyPressed event. How does that sound?

I am open to any suggestions 👍

d3lm avatar Jan 31 '20 10:01 d3lm

Hi there. :) Collegue of @andrzejkala here.

IMHO workaround with meta click is kind of OK, but on the longer run it's hacky. It would be cool to add something built-in.

My propositions:

  • Prevent click when selecting (as an option)
  • (also as option) Pass a callback, so the library can decide whether it was just a click, or it was a select action

It would be perfect if you could do it, but if you don't have time, you could point us places to edit or guide on what to remember when changing it, we could post a PR.

johny-gog avatar Feb 03 '20 11:02 johny-gog

Yep, I like your suggestion! I see if I can get that in ASAP 👍

d3lm avatar Feb 06 '20 09:02 d3lm

Hi there, yet another colleague of both @andrzejkala and @johny-gog. Have you made any progress on this? I ask because if not, I think we could post a PR for it relatively soon.

ghost avatar Mar 16 '20 08:03 ghost

Trying to work on it this weekend.

d3lm avatar Mar 18 '20 10:03 d3lm