npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@josefarias/hotwire_combobox

v0.3.2

Published

An autocomplete combobox implementation for Ruby on Rails apps using Hotwire.

Downloads

7,163

Readme

Easy and Accessible Autocomplete for Ruby on Rails

CI Gem Version

[!IMPORTANT] HotwireCombobox is at an early stage of development. It's nearing a beta release, but the API might change and bugs are expected. Please continue to use the library and report any issues in the GitHub repo.

Installation

First, make sure Turbo and Stimulus are configured and running properly on your app.

Then, add this line to your application's Gemfile and run bundle install:

gem "hotwire_combobox"

Finally, configure your assets:

Configuring JS

Before continuing, you should know whether your app is using importmaps or JS bundling in your asset pipeline.

Importmaps

Most apps using importmaps won't need any configuration. If things aren't working for you, read on.

In app/javascript/controllers/index.js you should have one of the following:

Either,

import { application } from "controllers/application" // or equivalent
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"

eagerLoadControllersFrom("controllers", application)

Or,

import { application } from "controllers/application" // or equivalent
import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"

lazyLoadControllersFrom("controllers", application)

Or,

import { application } from "controllers/application" // or equivalent

import HwComboboxController from "controllers/hw_combobox_controller"
application.register("hw-combobox", HwComboboxController)

JS bundling (esbuild, rollup, etc)

First, install the JS portion of HotwireCombobox from npm with one of the following:

yarn add @josefarias/hotwire_combobox
npm install @josefarias/hotwire_combobox

Then, register the library's stimulus controller in app/javascript/controllers/index.js as follows:

import { application } from "./application" // or equivalent

import HwComboboxController from "@josefarias/hotwire_combobox"
application.register("hw-combobox", HwComboboxController)

[!WARNING] Keep in mind you need to update both the npm package and the gem every time there's a new version of HotwireCombobox. You should always run the same version number on both sides.

Configuring CSS

This library comes with optional default styles. Follow the instructions below to include them in your app.

Read the docs section for instructions on styling the combobox yourself.

Default

This approach works for all setups. Simply add the stylesheet to your layout (this would go in your document's <head>):

<%= combobox_style_tag %>

This helper accepts any of the options you can pass to stylesheet_link_tag.

Sprockets

Require the styles in app/assets/stylesheets/application.css:

*= require hotwire_combobox

Docs

Visit the docs site for a demo and detailed documentation. If the site is down, you can run the docs locally by cloning the docs repo.

Notes about accessibility

This gem follows the APG combobox pattern guidelines with some exceptions we feel increase the usefulness of the component without much detriment to the overall accessible experience.

These are the exceptions:

  1. Users cannot manipulate the combobox while it's closed. As long as the combobox is focused, the listbox is shown.
  2. The escape key closes the listbox and blurs the combobox. It does not clear the combobox.
  3. The listbox has wrap-around selection. That is, pressing Up Arrow when the user is on the first option will select the last option. And pressing Down Arrow when on the last option will select the first option. In paginated comboboxes, the first and last options refer to the currently available options. More options may be loaded after navigating to the last currently available option.
  4. It is possible to have an unlabled combobox, as that responsibility is delegated to the implementing user.
  5. There are currently no APG guidelines for a multiselect combobox. We've introduced some mechanisms to make the experience accessible, like announcing multi-selections via a live region. But we'd welcome feedback on how to make it better until official guidelines are available.

It should be noted none of the maintainers use assistive technologies in their daily lives. If you do, and you feel these exceptions are detrimental to your ability to use the component, or if you find an undocumented exception, please open a GitHub issue. We'll get it sorted.

Contributing

Please read CONTRIBUTING.md.

License

The gem is available as open source under the terms of the MIT License.