Comments (4)
I just stumbled upon this merged PR, introducing a custom hotkey-fire
event. Would it be the way to go at this? If it is, it could be nice to get it documented somehow?
from hotkey.
Yeah the hotkey-fire event is used to provide custom behaviours other than clicking links and buttons.
Sorry we didn’t fully document that! Would you like to make a PR documenting it? That would be an awesome improvement!
from hotkey.
Yeah, it'd be really great to get some documentation on this - it seems like it would be a fairly common use? Having found the library today, that was the first thing I went looking for.
from hotkey.
I've added some documentation to the README: https://github.com/github/hotkey/blob/main/README.md#js
By default form elements (such as input,textarea,select) or elements with contenteditable will call focus() when the hotkey is triggered. All other elements trigger a click(). All elements, regardless of type, will emit a cancellable hotkey-fire event, so you can customize the behaviour, if you so choose:
for (const el of document.querySelectorAll('[data-shortcut]')) { install(el, el.dataset.shortcut) if (el.matches('.frobber')) { el.addEventListener('hotkey-fire', event => { // ensure the default `focus()`/`click()` is prevented: event.preventDefault() // Use a custom behaviour instead frobulateFrobber(event.target) }) } }
I'll close this for now as I think this is effectively solved. Let me know if you have any other questions or find any other issues and I'll be happy to help 🙂
from hotkey.
Related Issues (20)
- Hotkeys are fired when trying to type into a text field inside a custom element HOT 4
- Add support for class-name as `data-hotkey-scope`
- Add a special `Mod` character that translates to either `Meta` on Mac or `Control` on other platforms HOT 2
- Handle keypresses in elements with dotted ids HOT 1
- `eventToHotkeyString ` returns doubled "modifier" when "key" is a modifier
- Hotkey Mapper Tool accessibility improvements HOT 4
- Hotkey version 2 HOT 1
- Release action fails on publish to npm HOT 2
- `eventToHotKey` inconsistent `alt` key behaviour on Mac
- API alterations to allow injection of hotkey parsing and event processing HOT 4
- TypeError: Cannot read properties of undefined (reading 'startsWith')
- Hotkey version 3 HOT 4
- How might I make the user press the shortcut twice before running the keyDownHandler?
- Listen for some hotkeys on form fields
- Uncomment emulator secrets when vault token is minted HOT 1
- The / hotkey does not work HOT 9
- Add support for chords to mapper tool
- Add support for `event.code`
- Expose `hotkey` and `SequenceTracker` components
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hotkey.