-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
ref(container) add ellipsis support #105956
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
Conversation
| 'white-space', | ||
| p.whiteSpace ? p.whiteSpace : p.ellipsis ? 'nowrap' : undefined, | ||
| p.theme | ||
| )}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Responsive ellipsis values not correctly mapped to CSS
Medium Severity
The ellipsis prop is typed as Responsive<boolean>, allowing responsive objects like {base: true, md: false}. However, the implementation uses simple truthiness checks (p.ellipsis ? 'ellipsis' : undefined) which treat any object as truthy. When a responsive object is passed, it results in 'ellipsis' being applied unconditionally instead of mapping each breakpoint's boolean value to the corresponding CSS value. The responsive behavior is lost.
| rc( | ||
| 'text-overflow', | ||
| p.textOverflow ? p.textOverflow : p.ellipsis ? 'ellipsis' : undefined, | ||
| p.theme | ||
| )}; | ||
| ${p => | ||
| rc( | ||
| 'white-space', | ||
| p.whiteSpace ? p.whiteSpace : p.ellipsis ? 'nowrap' : undefined, | ||
| p.theme | ||
| )}; |
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
|
Not entirely sold on the approach... there is less utility as I have imagined initially |
| )}; | ||
| ${p => | ||
| rc( | ||
| 'white-space', | ||
| p.whiteSpace ? p.whiteSpace : p.ellipsis ? 'nowrap' : undefined, | ||
| p.theme | ||
| )}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: The text-overflow and white-space properties incorrectly use a ternary on the ellipsis prop. This bypasses responsive handling when ellipsis is an object, applying styles globally.
Severity: MEDIUM
🔍 Detailed Analysis
When the ellipsis prop is a responsive object (e.g., {xs: true, md: false}), the ternary expressions p.ellipsis ? 'ellipsis' : undefined and p.ellipsis ? 'nowrap' : undefined evaluate the object as truthy. This causes them to immediately return the string values 'ellipsis' or 'nowrap', bypassing the responsive styling function rc(). Consequently, text-overflow and white-space are applied globally across all breakpoints, contrary to the intended responsive behavior which is correctly implemented for the overflow property. This creates an inconsistent and buggy API for a newly introduced feature.
💡 Suggested Fix
Refactor the text-overflow and white-space style definitions to use the rc() utility function directly with a resolver, similar to how the overflow property is handled. This will ensure that when p.ellipsis is a responsive object, the styles are generated with the correct media queries. Avoid using a simple truthiness check on the p.ellipsis prop.
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/app/components/core/layout/container.tsx#L303-L309
Potential issue: When the `ellipsis` prop is a responsive object (e.g., `{xs: true, md:
false}`), the ternary expressions `p.ellipsis ? 'ellipsis' : undefined` and `p.ellipsis
? 'nowrap' : undefined` evaluate the object as truthy. This causes them to immediately
return the string values `'ellipsis'` or `'nowrap'`, bypassing the responsive styling
function `rc()`. Consequently, `text-overflow` and `white-space` are applied globally
across all breakpoints, contrary to the intended responsive behavior which is correctly
implemented for the `overflow` property. This creates an inconsistent and buggy API for
a newly introduced feature.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8369330
| 'textOverflow', | ||
| 'top', | ||
| 'width', | ||
| 'whiteSpace', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Text, we have this named wrap:
| white-space: ${p => (p.wrap ? p.wrap : p.ellipsis ? 'nowrap' : undefined)}; |
The more I think about it, the more I would like us to stay as close as possible to html attributes. For example, <Text bold> isn’t better than setting font-weight and <Text wrap=“nowrap”> isn’t better than <Text whiteSpace=“nowrap”>, especially if it works differently on Container and we also have a textWrap prop on Text.
I sometimes find myself looking at the implementation of our core components just to know which props exist because I can’t find what I’m looking for in auto complete. That’s partially because auto complete lists all html props so it’s not helpful, but also because I type fontWeight or textDecoration and don’t find anything because our props are named differently ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair feedback. I think we can pull usage and see if that sticks, or if it's not been a good addition.
|
Closing this because I'm not entirely sold on the solution |
Adds container ellipsis support for Container. This is an alternative pattern to using