---
title: Text truncate
description: TextTruncate cuts a single line of text with an ellipsis at the end or in the middle and shows the full text in a tooltip.
category: Utilities
related: [EllipsisContent, Text, Tooltip]
---

Source: https://clickhouse.design/click-ui/texttruncate

# Text truncate

TextTruncate keeps text on one line and cuts it with an ellipsis when it does not fit. While the text is cut off, the full text shows in a tooltip on hover and on keyboard focus. It replaces EllipsisContent and is available from Click UI 0.15.0.

## Example

## Props

| Prop             | Type                             | Default value | Description                                                                                                     |
| ---------------- | -------------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------- |
| children \*      | `ReactNode`                      | `required`    | The content to truncate. Must be a string when ellipsisPosition is "middle"                                     |
| ellipsisPosition | `"end" \| "middle"`              | `"end"`       | Where the ellipsis goes. "middle" keeps the end of the text visible, such as a file extension or an ID suffix   |
| trailingChars    | `number`                         | `8`           | Middle only. Number of characters kept after the ellipsis                                                       |
| maxWidth         | `string`                         | `undefined`   | Caps the width with any CSS length, for example 160px or 20ch                                                   |
| showTooltip      | `boolean`                        | `true`        | Shows the full text in a tooltip and adds a tab stop while truncated. Set to false in large lists or grid cells |
| tooltipContent   | `ReactNode`                      | `children`    | Tooltip content. Pass plain text when children holds links or buttons                                           |
| tooltipProps     | `{ side?, align?, sideOffset? }` | `undefined`   | Positions the tooltip, for example \{ side: "right" }                                                           |
| component        | `ElementType`                    | `"span"`      | Element or component to render as. A component must forward ref and spread props                                |
| className        | `string`                         | `undefined`   | Additional CSS class                                                                                            |

```tsx
import { TextTruncate } from '@clickhouse/click-ui'

<TextTruncate maxWidth="220px">
  A long service description that does not fit on one line
</TextTruncate>

<TextTruncate maxWidth="220px" ellipsisPosition="middle">
  quarterly-revenue-report-2026-final.parquet
</TextTruncate>
```

## Quick start

```tsx
import { TextTruncate } from '@clickhouse/click-ui'

function FileName({ name }: { name: string }) {
  return (
    <TextTruncate maxWidth='20ch' ellipsisPosition='middle'>
      {name}
    </TextTruncate>
  )
}
```

## Accessibility

While the text is cut off, TextTruncate becomes a tab stop so keyboard users can reach the tooltip. Inside a button, link, tab, menu item or option it adds no tab stop, and the tooltip is hover-only there. If `children` contains a link or button, pass plain text as `tooltipContent`; the component warns in the console when it is missing.

## Related components

- **EllipsisContent**: The older component that TextTruncate replaces.
- **Text**: For text that is allowed to wrap.
- **Tooltip**: Used to show the full text.

## Common use cases

### Long lists

Turn the tooltip off when many truncated items render at once, such as rows in a long list.

```tsx
import { TextTruncate } from '@clickhouse/click-ui'

function TableNames({ names }: { names: string[] }) {
  return names.map(name => (
    <TextTruncate key={name} maxWidth='180px' showTooltip={false}>
      {name}
    </TextTruncate>
  ))
}
```
