Skip to content

Conversation

jakst
Copy link
Contributor

@jakst jakst commented Nov 16, 2018

What: Vague documentation (issue #153 )

Why: To clarify usage to users

How: Added documentation

Checklist:

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

README.md Outdated
})
```

**Keyboard events**: There are three event types related to keyboard input - `keyPress`, `keyDown`, and `keyUp`. When firing these you need to reference an element in the DOM. If the event you want to trigger is not bound to a certain element, you can reference the `container` returned from `render`.
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for this. Remember that we're in dom-testing-library which does not have a concept of render. Also

If the event you want to trigger is not bound to a certain element

I can't think of a scenario where this makes sense...

Also, the example should probably set more than just the key, but it should set the code as well.

What if the example were:

fireEvent.keyDown(domNode, { key: 'Enter', code: 13})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, mental slip. This should probably be documented in react-testing-library as well.

Could there be any unintended consequences of leaving out the code? Maybe there should be a link to where one could find these codes, like https://keycode.info/

@alexkrolick
Copy link
Collaborator

If the event you want to trigger is not bound to a certain element

I can't think of a scenario where this makes sense...

To elaborate: DOM events "bubble up" from the target element to their parent and all the way up to the root element. They can be handled at any depth, even multiple times, unless a handler calls the event's stopPropagation() method. If you're thinking of a keypress as a global event, that means that the only event listener is at the root - the target element is whatever has focus when the event was triggered, and then it propagates up to the top.

@jakst
Copy link
Contributor Author

jakst commented Nov 18, 2018

@alexkrolick Thanks for the clarification. I actually never considered that keyboard events could be bound to other elements as I've used them very lightly and have always bound them to document.


<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=kentcdodds "Tests") | [<img src="https://avatars1.githubusercontent.com/u/2430381?v=4" width="100px;"/><br /><sub><b>Ryan Castner</b></sub>](http://audiolion.github.io)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=audiolion "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/8008023?v=4" width="100px;"/><br /><sub><b>Daniel Sandiego</b></sub>](https://www.dnlsandiego.com)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=dnlsandiego "Code") | [<img src="https://avatars2.githubusercontent.com/u/12592677?v=4" width="100px;"/><br /><sub><b>Paweł Mikołajczyk</b></sub>](https://github.com/Miklet)<br />[💻](https://github.com/kentcdodds/dom-testing-library/commits?author=Miklet "Code") | [<img src="https://avatars3.githubusercontent.com/u/464978?v=4" width="100px;"/><br /><sub><b>Alejandro Ñáñez Ortiz</b></sub>](http://co.linkedin.com/in/alejandronanez/)<br />[📖](https://github.com/kentcdodds/dom-testing-library/commits?author=alejandronanez "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1402095?v=4" width="100px;"/><br /><sub><b>Matt Parrish</b></sub>](https://github.com/pbomb)<br />[🐛](https://github.com/kentcdodds/dom-testing-library/issues?q=author%3Apbomb "Bug reports") [💻](https://github.com/kentcdodds/dom-testing-library/commits?author=pbomb "Code") [📖](https://github.com/kentcdodds/dom-testing-library/commits?author=pbomb "Documentation") [⚠️](https://github.com/kentcdodds/dom-testing-library/commits?author=pbomb "Tests") | [<img src="https://avatars1.githubusercontent.com/u/1288694?v=4" width="100px;"/><br /><sub><b>Justin Hall</b></sub>](https://github.com/wKovacs64)<br />[📦](#platform-wKovacs64 "Packaging/porting to new platform") |
Copy link
Member

Choose a reason for hiding this comment

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

Sorry! But please don't edit this table manually! It's generated. Please see the CONTRIBUTING.md file for instructions on how to generate and add yourself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Completely unintentional, sorry. Thought I saved without formatting...

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

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

Thank you! 💯

@kentcdodds kentcdodds merged commit 81299da into testing-library:master Nov 19, 2018
@kentcdodds
Copy link
Member

🎉 This PR is included in version 3.12.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants