Debian Codegraph @

node/@patternfly/patternfly/docs/components/Truncate/examples/Truncate.md

raw
1 ---
2 id: 'Truncate'
3 section: components
4 cssPrefix: pf-v6-c-truncate
5 ---import './Truncate.css'
6
7 ## Examples
8
9 The default behavior of the truncate component is to truncate based on whether the content can fit within the width of its parent container, and to prevent text from wrapping. The following examples that use this default behavior render the truncate component inside a resizable container, allowing you to see how the parent container width affects the truncation.
10
11 Note that when content is truncated, a tabindex of 0 should also be added to the element to ensure it remains accessible. The examples below however, add a tabindex in both cases as the content is static.
12
13 ### Default
14
15 When only the `.pf-v6-c-truncate__start` element is used, truncation will occur at the end of the string.
16
17 ```html
18 <div class="pf-v6-c-truncate--example">
19 <span class="pf-v6-c-truncate" tabindex="0">
20 <span
21 class="pf-v6-c-truncate__start"
22 >redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip</span>
23 </span>
24 </div>
25
26 ```
27
28 ### Middle
29
30 When both `.pf-v6-c-truncate__start` and `.pf-v6-c-truncate__end` elements are used, truncation will occur between the strings that are in each respective element. As the parent container width changes, the point at which content within the `.pf-v6-c-truncate__start` element is truncated will also change.
31
32 ```html
33 <div class="pf-v6-c-truncate--example">
34 <span class="pf-v6-c-truncate" tabindex="0">
35 <span
36 class="pf-v6-c-truncate__start"
37 >redhat_logo_black_and_white_reversed_simple_</span>
38 <span class="pf-v6-c-truncate__end">with_fedora_container.zip</span>
39 </span>
40 </div>
41
42 ```
43
44 ### Start
45
46 When only the `.pf-v6-c-truncate__end` element is used, truncation will occur at the start of the string. `&lrm;` **must** be included at the end of a string to denote the ending punctuation mark, otherwise it will render at the start of the truncated content.
47
48 ```html
49 <div class="pf-v6-c-truncate--example">
50 <span class="pf-v6-c-truncate" tabindex="0">
51 <span
52 class="pf-v6-c-truncate__end"
53 >redhat_logo_black_and_white_reversed_simple_with_fedora_container.zip</span>
54 </span>
55 </div>
56
57 ```
58
59 ### Based on max characters
60
61 Apply the `.pf-m-fixed` class to the `.pf-v6-c-truncate` element to implement truncation based on a fixed amount of characters rather than a parent container width.
62
63 ```html
64 <div>Truncated at end position:</div>
65 <span class="pf-v6-c-truncate pf-m-fixed" tabindex="0">
66 <span
67 class="pf-v6-c-truncate__text"
68 >redhat_logo_black_and_white_reversed_simple_with_</span>
69 <span class="pf-v6-c-truncate__omission" aria-hidden="true">&hellip;</span>
70 <span class="pf-v6-screen-reader">fedora_container.zip</span>
71 </span>
72 <br />
73 <br />
74 <div>Truncated at middle position:</div>
75 <span class="pf-v6-c-truncate pf-m-fixed" tabindex="0">
76 <span class="pf-v6-c-truncate__text">redhat_logo_black_and_</span>
77 <span class="pf-v6-screen-reader">white_reversed_simple_with_</span>
78
79 <span class="pf-v6-c-truncate__omission" aria-hidden="true">&hellip;</span>
80 <span class="pf-v6-c-truncate__text">fedora_container.zip</span>
81 </span>
82 <br />
83 <br />
84 <div>Truncated at start position:</div>
85 <span class="pf-v6-c-truncate pf-m-fixed" tabindex="0">
86 <span class="pf-v6-screen-reader">redhat_logo_black_</span>
87
88 <span class="pf-v6-c-truncate__omission" aria-hidden="true">&hellip;</span>
89 <span
90 class="pf-v6-c-truncate__text"
91 >and_white_reversed_simple_with_fedora_container.zip</span>
92 </span>
93
94 ```
95
96 ## Documentation
97
98 ### Usage
99
100 | Class | Applied | Outcome |
101 | -- | -- | -- |
102 | `.pf-v6-c-truncate` | `<span>` | Initiates the truncate component. **Required** |
103 | `.pf-v6-c-truncate__start` | `<span>` | Defines the truncate component starting text. **Required** when using default/end or middle truncation, **except** for when the `.pf-m-fixed` class is applied to the `.pf-v6-c-truncate` element. |
104 | `.pf-v6-c-truncate__end` | `<span>` | Defines the truncate component ending text. **Required** when using start or middle truncation, **except** for when the `.pf-m-fixed` class is applied to the `.pf-v6-c-truncate` element. |
105 | `.pf-v6-c-truncate__text` | `<span>` | Defines the visible truncate component text. **Required** and should only be used when the `.pf-m-fixed` class is applied to the `.pf-v6-c-truncate` element. |
106 | `.pf-m-fixed` | `.pf-v6-c-truncate` | Modifies the truncate component to base truncation on a fixed amount of characters rather than container width. |