Truncate

Use truncate to shorten overflowing text with an ellipsis.
  • Beta
  • Not reviewed for accessibility

Use Truncate to shorten overflowing text with an ellipsis.

Arguments

NameTypeDefaultDescription
system_argumentsHashN/ASystem arguments

Slots

items

Text slot used for the truncated text.

NameTypeDefaultDescription
priorityBooleanN/Aif true, the text will be given priority
expandableBooleanN/Aif true, the text will expand on hover or focus
max_widthIntegerN/Aif provided, the text will be truncated at a maximum width
system_argumentsHashN/ASystem arguments

Examples

Default

branch-name-that-is-really-long
<%= render(Primer::Beta::Truncate.new) { "branch-name-that-is-really-long" } %>

Multiple items

really-long-repository-owner-name / really-long-repository-name
<%= render(Primer::Beta::Truncate.new) do |component| %>
<% component.with_item do %>really-long-repository-owner-name<% end %>
<% component.with_item(font_weight: :bold) do %>
<%= render(Primer::BaseComponent.new(tag: :span, font_weight: :normal)) { "/" } %> really-long-repository-name
<% end %>
<% end %>

Advanced multiple items

  1. primer
  2. / css
  3. / Issues
  4. / #123 —
  5. Visual bug on primer.style found in lists
<%= render(Primer::Beta::Truncate.new(tag: :ol)) do |component| %>
<% component.with_item(tag: :li) do %>primer<% end %>
<% component.with_item(tag: :li, priority: true) do %>/ css<% end %>
<% component.with_item(tag: :li) do %>/ Issues<% end %>
<% component.with_item(tag: :li) do %>/ #123 —<% end %>
<% component.with_item(tag: :li, priority: true) do %>
Visual bug on primer.style found in lists
<% end %>
<% end %>

Expand on hover or focus

<%= render(Primer::Beta::Truncate.new) do |component| %>
<% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
<% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
<% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
<% component.with_item(tag: :a, href: "#", expandable: true) do %>really-long-repository-owner-name<% end %>
<% end %>

Max widths

branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long
<%= render(Primer::Beta::Truncate.new) do |component| %>
<% component.with_item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% component.with_item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% component.with_item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>

Max widths on new lines

branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long
branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long
branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long
<%= render(Primer::Beta::Truncate.new) do |component| %>
<% component.with_item(max_width: 300, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>
<br/>
<%= render(Primer::Beta::Truncate.new) do |component| %>
<% component.with_item(max_width: 200, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>
<br/>
<%= render(Primer::Beta::Truncate.new) do |component| %>
<% component.with_item(max_width: 100, expandable: true) do %>branch-name-that-is-really-long-branch-name-that-is-really-long-branch-name-that-is-really-long<% end %>
<% end %>