Truncate component breaks JSX conventions
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 140
- Forks
- 100
- Avg merge
- 1h 3m
- Merged PRs (30d)
- 30
Description
Feedback summary
The <Truncate> component documentation says:
Note: Truncate supports only plain HTML children and not jsx.
And a supposed example of this can be seen in the "HTML markdown support" section.
However, this is not true. A more accurate statement would be "Truncate supports only a buggy, idiosyncratic version of JSX."
It is JSX, not HTML
First of all, if it was truly HTML instead of JSX, it would have to be passed into the Truncate component as a string; it is in fact being parsed by React's JSX parser. You can clearly see this if you use other JSX syntax like {"string interpolation"}:
Bugs
Second, of all, it throws errors on things that are perfectly valid HTML or JSX:
Incompatibility
Finally, because this is actually JSX but it's not implemented correctly, TypeScript is always going to throw errors like this (which is how I discovered all this):
Type '{ children: Element; class: string; }' is not assignable to type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'.
Property 'class' does not exist on type 'DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>'. Did you mean 'className'?
I don't think it is possible to tell TypeScript that some portion of the JSX is using our own special version of JSX and should be using class instead of className.
Suggestion
At the very least, I suggest fixing the bugs and implementing support for className instead of class, htmlFor instead of for, etc. so that we can use this with TypeScript.
But now might be the time to replace the current complex JS implementation with a simple CSS implementation, given that all major browsers have supported -webkit-line-clamp for a while (click "Usage Relative").
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Truncate component and its documentation, especially the “HTML markdown support” section, then reproduce the JSX and TypeScript errors described in the issue. Done would require an agreed scope for correcting JSX behavior, updating the documentation, and verifying the supported syntax; the issue does not name implementation files or tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- css, javascript, react, typescript
- Domain
- documentation, frontend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100