-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add onLeftArrow and onRightArrow props #971
Add onLeftArrow and onRightArrow props #971
Conversation
:) Thanks for the great commit message and for contributing @kedromelon! I'm curious what your Draft use case is, and how you would use You are right that it seems silly to expose I am still thinking about the question of how to be consistent once we have made that change - it looks like Some options we may consider;
Either way it would be nice to add an example, or at least know some possible use cases for these props. Sidenote: |
Just thought I'd chime in hear. We've created our own version of atomic blocks, that are selectable. In order for them to be that, and still play nicely with the "normal selection", we need to tell Draft what to do with the different arrow key events. We also have to see if Some more thoughts about the arrow events: the recommendation seems to be to use the Having said that, I think @flarnie's second option sounds best, since all key events would be handled, and named, in a similar way. For someone unfamiliar with the code base, I don't think it's clear how and why |
@tobiasandersen Yep! I have a similar use case. Essentially trying to create Medium-like selection of Atomic Blocks, not unlike what was discussed in #203. I would agree that @flarnie's second option sounds better. As mentioned above, having all of these "handlers" (for lack of a better term) named I'll try to see if I can get an isolated example put together soon. Thanks for the input, @flarnie and @tobiasandersen! |
Okay, got a chance to put together an example. Essentially, what I'm trying to illustrate is the inconsistent API between up/down and left/right arrows. In the example, I want to handle key commands myself when the cursor is adjacent to an atomic block. |
Thanks for your patience on this PR - I have been following the conversation, and need to fix some other issues with Draft before giving this my full attention. It is still on my radar. |
👌 no rush! was able to work around it just fine for my use case, but i do think this API is worth improving. |
Just wanted to put in a vote in favor of this solution. I have been using draft-js for the past months for a project and have found the API for custom key handling inconsistent. I would prefer a one-way-to-rule-them all API. |
🎉 saw this functionality was merged in #1384! gonna close this issue. |
Summary
While implementing some custom selection logic, I found it somewhat unintuitive that
onUpArrow
andonDownArrow
are exposed as props, butonLeftArrow
andonRightArrow
are not.Given the added complexity due to the workaround needed by firefox for handling CMD+LEFT/RIGHT, it seems to me that it may make sense to have these handlers return
DraftHandleValue
(likehandleReturn
, etc) so that they can still fall through togetDefaultKeyBinding
.Is this appropriate? If so, would these props be better named
handleLeftArrow
andhandleRightArrow
? Should any otheron*
props be refactored to use this logic?Test Plan
As far as I can tell there are no existing tests for the modified files. Did I miss any? Should any be added?
Thanks for taking the time to check out this PR!