Guidelines
Recommendations when cutting it short.
Though truncation should be used infrequently there are situations where the user can benefit from seeing a preview of data. For example, a user may want to skim through the beginning of multiple reviews before deciding to view one in its entirety.
In Thumbtack products there are four types of truncation in use:
In this case a few lines of well-supported CSS is sufficient. The truncate
class is available in our Atomic library to make this easy.
.truncate {white-space: nowrap;overflow: hidden;text-overflow: ellipsis;}
This type of truncation is more complicated with no one perfect solution. There are a number of Sass and JavaScript approaches but they are often convoluted and limited. In this case we recommend a Sass approach that uses line-height
tokens to calculate a max-height
.
.multiline {font-size: $tp-font__title__3__size; // Needed for IE 11line-height: $tp-font__title__3__line-height; // Needed for IE 11max-height: $tp-font__title__3__line-height * 2; // Needed for IE 11overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;}
-webkit-line-clamp
.Because the Sass pattern for multiline truncation described above relies on a max-height
calculation, it can visually break if the size of the text container changes unexpectedly. To insulate against this we recommend the following:
Note that this approach means that the truncation will often not occur at the end of a line.
This is a standard Javascript interaction to show/hide multiple elements in a list. The number of elements to hide and reveal should be at the discretion of the designer and developer, keeping in the mind the following: