Widgets

Chip

Chip

A compact element for an attribute, filter, or action. Chips are commonly shown in a row and can be selectable or deletable.

Example

row(
  spacing: 8,
  children: %w[All Open Closed].map do |label|
    chip(
      label: text(label),
      selected: label == "Open",
      on_click: ->(_e) { set_filter(label) }
    )
  end
)

Common properties

  • label — the chip's content control
  • selected / selected_color
  • leading — a leading control (often an avatar or icon)
  • show_checkmark
  • delete_icon / on_delete — make the chip deletable
  • bgcolor
  • shape
  • border_side

Usage

Read or toggle selected to drive filter UIs. Add a delete_icon and handle on_delete for removable tags.

Complete API

Helpers

  • chip(label = ..., **props)

Accepted properties

  • align — Alignment of the control within its parent.
  • animate_align — Animates alignment changes.
  • animate_margin — Animates margin changes.
  • animate_offset — Animates offset changes.
  • animate_opacity — Animates opacity changes.
  • animate_position — Animates position changes.
  • animate_rotation — Animates rotation changes.
  • animate_scale — Animates scale changes.
  • animate_size — Animates size changes.
  • aspect_ratio — Width-to-height ratio to maintain.
  • autofocus — Requests focus when first shown.
  • badge — Badge drawn on the corner of the control.
  • bgcolor — Background color.
  • border_side — Sets the border side property.
  • bottom — Bottom offset when positioned inside a stack.
  • check_color — Check color.
  • clip_behavior — How content overflowing the bounds is clipped.
  • col — Responsive column span (1-12) per breakpoint.
  • color — Foreground color.
  • data — Arbitrary value you can attach to the control and read back in handlers.
  • delete_drawer_animation_style — Delete drawer animation style.
  • delete_icon — Delete icon.
  • delete_icon_color — Delete icon color.
  • delete_icon_size_constraints — Sets the delete icon size constraints property.
  • delete_icon_tooltip — Sets the delete icon tooltip property.
  • disabled — Disables interaction when true.
  • disabled_color — Disabled color.
  • elevation — Shadow depth (z-height).
  • elevation_on_click — Sets the elevation on click property.
  • enable_animation_style — Enable animation style.
  • expand — Fills the available space along the parent's main axis when true.
  • expand_loose — Like expand, but only grows up to the child's natural size.
  • height — Fixed height in logical pixels.
  • key — Stable identity used to preserve state across rebuilds.
  • label — Text label shown for the control.
  • label_padding — Label padding.
  • label_text_style — Label text style.
  • leading — Control placed before the main content (e.g. an icon or avatar).
  • leading_drawer_animation_style — Leading drawer animation style.
  • leading_size_constraints — Sets the leading size constraints property.
  • left — Left offset when positioned inside a stack.
  • margin — Outer spacing around the control.
  • offset — Translation offset applied to the control.
  • opacity — Opacity from 0.0 (transparent) to 1.0 (opaque).
  • padding — Inner spacing between the border and the content.
  • right — Right offset when positioned inside a stack.
  • rotate — Rotation applied to the control.
  • rtl — Renders right-to-left when true.
  • scale — Scale transform applied to the control.
  • select_animation_style — Select animation style.
  • selected — Whether the control is selected.
  • selected_color — Selected color.
  • selected_shadow_color — Selected shadow color.
  • shadow_color — Color of the drop shadow.
  • shape — Shape/border of the control.
  • show_checkmark — Sets the show checkmark property.
  • size_change_interval — Throttle interval for on_size_change, in ms.
  • tooltip — Text shown on hover/long-press.
  • top — Top offset when positioned inside a stack.
  • visible — Hides the control when false.
  • visual_density — Compactness of the control's layout.
  • width — Fixed width in logical pixels.

Events

  • on_animation_end — Fired when an animation completes.
  • on_blur — Fired when the control loses focus.
  • on_click — Fired when the control is clicked/tapped.
  • on_delete — Fired on delete.
  • on_focus — Fired when the control gains focus.
  • on_select — Fired when a selection is made.
  • on_size_change — Fired when the control's size changes.

Wire reference

  • Family: materials
  • Widget type: chip