Filter Edit

Displays a list that is filterable via the included input.

Examples

Ruby on Rails
Next.js
Remix.run

Installation


  rails generate shadcn-ui filter

Usage

<%= render_filter items do %>
  <%# Optional  %>
  <%= filter_icon do %>
  <% end %>
<% end >

The Filter component introduces:

  • app/helpers/components/filter_helper.rb
  • app/views/components/ui/_filter.html.erb
  • app/javascript/controllers/ui/filter_controller.js

The method render_filter method accepts one mandatory argument, an array of hashes that each have a value and name name.

You can also use the pattern argument to provide a regular expression as a string. It requires the placeholder {input} to dynamically insert a term into the regex. By default, it is set to ^{input}, meaning the input term will match only at the beginning of a string. Ensure {input} is included in custom patterns to maintain proper functionality.

You can optionally also call filter_icon within a block passed to render_filter to render an icon to the left of the filter input.

This component gets used in the Combobox and Command components as well as potentially others.

Ruby on Rails
Next.js
Remix.run