Skip to content

Commit e867938

Browse files
feat: add splitOnChars options fix issue #2
1 parent 0216b01 commit e867938

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Clampy(props) {
2525
const options = {
2626
clamp: props.clampSize,
2727
truncationChar: props.truncationChar,
28+
splitOnChars: props.splitOnChars,
2829
// truncationHTML: truncationHTML,
2930
// Clampy will try to use native clamp if available in the browser
3031
// however this can leads to unexpected results so we need to explicitely
@@ -40,7 +41,7 @@ function Clampy(props) {
4041
clampy.clamp(containerRef.current, options);
4142
setOpacity(1);
4243
}
43-
}, [initialContent, props.clampSize, props.truncationChar]);
44+
}, [initialContent, props.clampSize, props.truncationChar, props.splitOnChars]);
4445

4546
useEffect(() => {
4647
truncate();
@@ -72,12 +73,14 @@ function Clampy(props) {
7273
Clampy.propTypes = {
7374
children: PropTypes.node,
7475
clampSize: PropTypes.string,
75-
truncationChar: PropTypes.string
76+
truncationChar: PropTypes.string,
77+
splitOnChars: PropTypes.array
7678
};
7779

7880
Clampy.defaultProps = {
7981
clampSize: "auto", // Default clamp size based on available height
80-
truncationChar: "…"
82+
truncationChar: "…",
83+
splitOnChars: ['.', '-', '–', '—', ' '],
8184
// truncationHTML: ''
8285
};
8386

0 commit comments

Comments
 (0)