Skip to content

Add 'wordBreak' option to prevent cutting words #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ In some upcoming version it may be able to detect this value automatically.

| property | type | default | description |
| --- | --- | --- | --- |
| importCss | Boolean | false | Set to `true` in order to import styles into `<head>` automatically, element.style is used by default
| importCss | Boolean | `false` | Set to `true` in order to import styles into `<head>` automatically, element.style is used by default
| textOverflow | String | `ellipsis` | Set the value for [`text-overflow`](https://developer.mozilla.org/en-US/docs/Web/CSS/text-overflow) property in modern browsers
| fallbackFunc | Function | defaultFallbackFunc | Provide your own default method to handle the truncation strategy on unsupported browsers. Accepts all directive params: `element (Node)`, `bindings (Object)`, `lines (Number)`
| wordBreak | Boolean | `true` | Break words by using [`word-break`](https://developer.mozilla.org/en-US/docs/Web/CSS/word-break) property.
| fallbackFunc | Function | `defaultFallbackFunc` | Provide your own default method to handle the truncation strategy on unsupported browsers. Accepts all directive params: `element (Node)`, `bindings (Object)`, `lines (Number)`


### Caveats
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const truncateText = function(el, bindings, useFallbackFunc) {
const VueLineClamp = {
install(Vue, options) {
options = Object.assign(
{ importCss: false, textOverflow: 'ellipsis' },
{ importCss: false, textOverflow: 'ellipsis', wordBreak: true },
options
);

Expand All @@ -48,7 +48,7 @@ const VueLineClamp = {
display: -webkit-box;
-webkit-box-orient: vertical;
overflow: hidden;
word-break: break-all;
${options.wordBreak ? 'word-break: break-all;' : ''};
text-overflow: ${options.textOverflow};
`;

Expand Down