0.01
A long-lived project that still receives updates
No dependencies. No configuration. Just HTML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

>= 7.0
 Project Readme

Hotkeys Rails

Gem Version CI

Keyboard shortcuts for Hotwire apps. No dependencies. No configuration. Just HTML.

Installation

Add to your Gemfile:

gem "hotkeys-rails"

Run:

bundle install
rails generate hotkeys_rails:install

Usage

<%= link_to "Back", root_path, hotkey: :esc %>
<%= button_to "New Card", cards_path, hotkey: :c %>
<%= button_tag "Save", hotkey: [:ctrl, :enter] %>

The :ctrl modifier binds both Ctrl (Windows/Linux) and Cmd (Mac).

Visual Hints

<%= link_to cards_path, hotkey: :c do %>
  Add a card <%= hotkey_hint(:c) %>
<% end %>

Labels for Tooltips

<%= button_tag "Save",
      title: "Save (#{hotkey_label(:ctrl, :enter)})",
      hotkey: [:ctrl, :enter] %>

Focus Instead of Click

<%= text_field_tag :search, data: hotkey(:f, action: :focus) %>

Works with Other Data Attributes

<%= link_to "Edit", edit_path,
      hotkey: :e,
      data: { turbo_frame: "modal" } %>

Helpers

  • hotkey(*keys) - Returns data attributes for Stimulus controller
  • hotkey_label(*keys) - Platform-aware label (⌘ on Mac, Ctrl+ elsewhere)
  • hotkey_hint(*keys) - Renders <kbd> element with hide-on-touch class

How It Works

This gem overrides link_to, button_to, and button_tag to support the :hotkey option. When you use hotkey: :esc, it extracts the option and merges the Stimulus data attributes into the element.

If you prefer explicit control, use the hotkey() helper directly:

<%= link_to "Back", root_path, data: hotkey(:esc) %>

License

MIT