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

action inside list block #1069

Open
0000marcell opened this issue Feb 21, 2018 · 5 comments
Open

action inside list block #1069

0000marcell opened this issue Feb 21, 2018 · 5 comments

Comments

@0000marcell
Copy link
Contributor

is there a way to insert a button with an action inside the list and have this action called without selecting the item.
something like this

{#power-select-multiple  
  selected=selectedTags
  searchField="name"
  selectedItemComponent="selected-item-tag"
  onkeydown=(action "handleKeydown")
  options=tags onchange=(action "selectTag") 
  as |item|}}
  <div class="flex-row inline-space-between">
    {{item.name}}
    <a {{action "removeTag" item bubbles=false}}>x</a>
  </div>
{{/power-select-multiple}}

i've tried with bubbles=false and capturing the event and calling even.stopPropagation(),
but the selection is always called first 😢

@cibernox
Copy link
Owner

Yes, there is. What is tripping you is that the options are not selected on click, but on mousedown (seems weird, but this is how it should be to behave like native selects do).

What I recommend is to prevent the propagation of the mouseup but still file the button's action on click:

{#power-select-multiple  
  selected=selectedTags
  searchField="name"
  selectedItemComponent="selected-item-tag"
  onkeydown=(action "handleKeydown")
  options=tags onchange=(action "selectTag") 
  as |item|}}
  <div class="flex-row inline-space-between">
    {{item.name}}
    <a onmouseup={{action "stopPropagation"}} onclick={{action "removeTag"}}>x</a>
  </div>
{{/power-select-multiple}}

@0000marcell
Copy link
Contributor Author

Thx a lot Miguel, what do you think about adding this info to the docs? i think its a pretty common use case and is hard to figure out alone, at least it was for me, i'm probably will have to come back here to remember what i need to do, maybe adding this info to "the list" section of the docs, i could open a PR if you think its a good idea.

@cibernox
Copy link
Owner

cibernox commented Feb 27, 2018

Sure, although I'm not sure where to put it. I am biased about my own docs, where would you have looked for this information? That is where is should be.

@0000marcell
Copy link
Contributor Author

I think "basic customization > the list" is the best place to put it, a new topic called "prevent click propagation" what do you think ?

@cibernox
Copy link
Owner

Could work, yes. Do you want to make a PR? The documentation is just the dummy app inside this repo. It's pretty straightforward.

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