Skip to content

Instantly share code, notes, and snippets.

@freddi301
Created October 20, 2021 15:40
Show Gist options
  • Save freddi301/084c097c90b6647b810cae4f04594cb4 to your computer and use it in GitHub Desktop.
Save freddi301/084c097c90b6647b810cae4f04594cb4 to your computer and use it in GitHub Desktop.
truncates single line to parent width
import React from "react";
export function TruncatedLine({ text }: { text: string }) {
return (
<span style={{ position: "relative", display: "block" }}>
<span style={{ color: "transparent" }}>X</span>
<span
style={{
display: "block",
position: "absolute",
overflow: "hidden",
textOverflow: "ellipsis",
whiteSpace: "nowrap",
width: "100%",
top: 0,
}}
>
{text}
</span>
</span>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment