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 can I disable Keyboard Scrolling? #52

Closed
ghost opened this issue Jan 11, 2016 · 9 comments
Closed

How can I disable Keyboard Scrolling? #52

ghost opened this issue Jan 11, 2016 · 9 comments

Comments

@ghost
Copy link

ghost commented Jan 11, 2016

Each of the rows i'm putting in the VirtualScroll contain a selectable dropdown where the user can select options with his keyboard.
However, pressing the down button, starts to scroll the VirtualScroll List.

Would disabling this scroll fix the issue for me?

@bvaughn
Copy link
Owner

bvaughn commented Jan 11, 2016

Ah, right. Currently it is not possible to disable keyboard scrolling for a VirtualScroll component. I could add such a feature if needed but I don't think you need it in this case. In your keyboard event handler, if you decide that an event has meaning (like an up/down arrow), then you can stop it from bubbling up to VirtualScroll like so:

event.preventDefault()
event.stopPropagation()

@bvaughn
Copy link
Owner

bvaughn commented Jan 11, 2016

Going to close this as answered for now. Please let me know if you still have questions though :)

@bvaughn bvaughn closed this as completed Jan 11, 2016
@ghost
Copy link
Author

ghost commented Jan 11, 2016

Yeah no worries abwt closing it :)
I'm not sure though i understand how I would implement the bubbling of the event. I do not currently have an keyboard event handler.
Could u provide a sample case? Pseudo code would do :)

@bvaughn
Copy link
Owner

bvaughn commented Jan 11, 2016

Ah, I see.

I am suggesting that you could listen for the event you care about (in this case the keyboard event) and prevent it from getting up to the VirtualScroll parent if you want to prevent the default behavior.

@ghost
Copy link
Author

ghost commented Jan 11, 2016

yeah but that's annoying cuz then i'd need to pass it to the other library i want to listen to that even.
What if i did a manual disable of that in the react-virtualized source code? Is there a method that if removed would disable the even listening?

@bvaughn
Copy link
Owner

bvaughn commented Jan 11, 2016

No, you wouldn't. You could just wrap the other library you're using and stop up/down arrow events from bubbling up any further. Something like...

<VirtualScroll>
  <div onKeyDown={yourEventHandler}>
    <TheOtherLibrary/>
  </div>
</div>

@jquense
Copy link
Contributor

jquense commented Feb 2, 2016

I'm taking a look at using the VirtualScroll component but the lack of bubbling events is a dealbreaker. IN our case I need the key events to propagate to a higher component that manages state like the currently selected cell, (think like excel's keyboard navigation). I appreciate the value that the keyboard scroll adds...is the stopPropagation necessary? PreventDefault should already kill any scroll behavior no?

@bvaughn
Copy link
Owner

bvaughn commented Feb 2, 2016

Good suggestion, @jquense. I believe you're right. :)

@bvaughn
Copy link
Owner

bvaughn commented Feb 2, 2016

@jquense check out 4.6.1. I've removed stopPropagation and left preventDefault as you suggested.

bvaughn added a commit that referenced this issue Feb 3, 2016
…ary to prevent keyboard event bubbling, only to prevent the default browser behavior. Built as 4.6.1.
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