mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-14 18:01:06 +00:00
fix(truncate): preserve existing class names on node (#541)
This commit is contained in:
parent
66a3fd10c2
commit
24e36a7fd0
1 changed files with 7 additions and 1 deletions
|
@ -11,8 +11,14 @@
|
|||
* <h1 use:truncate={{ clamp: "front" }}>...</h1>
|
||||
*/
|
||||
export function truncate(node, params = {}) {
|
||||
const prefix = "bx--text-truncate--";
|
||||
|
||||
function toggleClass(front = false) {
|
||||
node.className = `bx--text-truncate--${front ? "front" : "end"}`;
|
||||
const classes = [...node.classList]
|
||||
.filter((name) => !name.startsWith(prefix))
|
||||
.join(" ");
|
||||
|
||||
node.className = `${classes} ${prefix}${front ? "front" : "end"}`;
|
||||
}
|
||||
|
||||
toggleClass(params.clamp === "front");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue