Skip to content

Add docs for default keydown handlers - #370

Merged
kentcdodds merged 2 commits into
downshift-js:masterfrom
indiesquidge:keydown-handlers-docs
Mar 20, 2018
Merged

kentcdodds merged 2 commits into
downshift-js:masterfrom
indiesquidge:keydown-handlers-docs

Conversation

@indiesquidge

@indiesquidge indiesquidge commented Mar 12, 2018 •

Copy link
Copy Markdown
Contributor

What:

Add documentation for Downshift's internal keydown handlers.

Why:

Due to a number of issues being raised and comments being written on the topic of keydown events when using Downshift, it seems like a good idea to document Downshift's implicit keydown handlers. This compliments nicely with the section already written about how to customize or circumvent Downshift's internal event handlers (re: #358)

How:

Added a section in the README outlining what each keydown handler does by default.

Checklist:

  • Documentation
  • Tests N/A
  • Ready to be merged
  • Added myself to contributors table

You'll note that I have not yet checked "Ready to be merged". This is due to an outstanding question on the expected behavior of the 'Escape' keydown event (see #336 (comment))

Comment thread README.md
3. Update the title and description
4. Update the code for your example (add some form of documentation to explain
what it is)
5. Add the tag: `downshift:example`

@indiesquidge indiesquidge Mar 12, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand what's causing some of these changes.

Everything other than the chunk added about the default event handlers is being added automatically after I run and complete the add-contributor script. I can split the changes into two commits to show this if need be.

Some of these spacing changes are innocuous, but it seems like the automated changes being made to the contributors table are swapping out absolute paths with local paths (e.g. https://github.com/paypal/downshift/ is replaced with just /paypal/downshift/), which could be more of an issue. In either case, the changes don't belong.

If someone has a clue as to why this is happening, I'd like to remove these undesired changes from this pull request.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't add the spaces manually? That's interesting...

Also, I'm not sure what caused the paths to change from absolute to local, but I have seen this behavior in previous add-contributor commits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm pretty sure that prettier was updated since it was last run on this file or something. I'm not really concerned, but I am a bit confused by that.

I'm pretty sure what caused this this pr. I've released a fix to all-contributors-cli. If you reinstall dependencies then run ./node_modules/.bin/kcd-scripts contributors generate it should get fixed up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you, @austintackaberry and @kentcdodds. The change made to the executable module worked. Should be good for another review now :)

@codecov-io

codecov-io commented Mar 12, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #370 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #370   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           4      4           
  Lines         335    335           
  Branches       87     87           
=====================================
  Hits          335    335

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6e11ef3...2c1c0ad. Read the comment docs.

@kentcdodds kentcdodds left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Thanks

Comment thread README.md Outdated

Downshift has a few events for which it provides implicit handlers. All of these
handlers prevent the default event action, and a few of them have additional
functionality.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we rephrase this to be something more like:

Downshift has a few events for which it provides implicit handlers. Several of these handlers call `event.preventDefault()`. Their additional functionality is described below.

Comment thread README.md Outdated
* `Enter`: if the menu is open, select the currently highlighted item. NOTE: as
stated above, the usual 'Enter' event is prevented by Downshift's default implicit
enter handler, so, for example, a form submission event will not work as one
might expect. See below for customizing the handlers.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only true for when the menu is open. If the menu is closed then event.preventDefault() will not be called and form submission should work.

Comment thread README.md Outdated

* `Escape`: will close the menu, set the highlighted index to the
`defaultHighlightedIndex`, and "reset" the input value to the previous selected
item.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we call this more generally "reset" so we can simply say:

`Escape`: will reset downshift's state. This means that `highlightedIndex` will be set to the `defaultHighlightedIndex`, the `inputValue` will be set to the `itemToString` value of the `selectedItem`, and the `isOpen` state will be set to `false`.

@kentcdodds kentcdodds left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few things. Thanks for your work on this!

Comment thread README.md Outdated

* `ArrowDown`: moves the highlighted index down by 1. If this shift key is held
when this event fires, the highlighted index will jump down 5 indices instead of 1.
NOTE: if the current highlighed index is within the bottom 4 indices, the top-most

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite accurate. For example, if you're on the second to last item and arrow down with the shift key you will be placed at the forth item. It's always a movement of 5 regardless of where you are in the last. You might say it's the equivalent of doing the same action 5 times.

@indiesquidge indiesquidge Mar 18, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, if you're on the second to last item and arrow down with the shift key you will be placed at the forth item. It's always a movement of 5 regardless of where you are in the last.

Hmm, this isn't the behavior that I observe. I get the same behavior that was the point of confusion in #336, namely, if any of the final 5 indices (which I actually did mistype here when I wrote 4) are highlighted and the shift key is held when an ArrowDown event is fired, the top-most index is highlighted (and vice versa for ArrowUp with shift).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's odd... I could have sworn the logic what do as I suggested. Maybe I changed it and forgot? 🤔 Or maybe there's something weird with that example.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked. Looks like that's the logic alright. I'm ok with that. This is a rarely used feature anyway and I think both behaviors are just as reasonable as the other. This is fine! Thanks!

Comment thread README.md Outdated

* `ArrowUp`: moves the highlighted index up by 1. If this shift key is held when
this event fires, the highlighted index will jump up 5 indices instead of 1. NOTE:
if the current highlighed index is within the top 4 indices, the bottom-most index

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment thread README.md Outdated

* `Enter`: if the menu is open, select the currently highlighted item. If the menu
is open, the usual 'Enter' event is prevented by Downshift's default implicit enter
handler; so, for example, a form submission event will not work as one might expect.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add at the end of this sentence (though if the menu is closed the form submission will work normally)

@indiesquidge indiesquidge Mar 18, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I figured I had this caveat covered by changing the start of the sentence to "If the menu is open…". Would you prefer I remove that and add your suggestion to the end, or just add this to the end but leave the beginning as is?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's just make the addition I suggested. I feel like it could be ambiguous otherwise.

@kentcdodds kentcdodds left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you!

@kentcdodds
kentcdodds merged commit d2df6ec into downshift-js:master Mar 20, 2018
@indiesquidge
indiesquidge deleted the keydown-handlers-docs branch March 20, 2018 20:20
Rendez pushed a commit to Rendez/downshift that referenced this pull request Sep 30, 2018
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

Successfully merging this pull request may close these issues.

4 participants