-
Notifications
You must be signed in to change notification settings - Fork 11.1k
fix(web): prevent list cell text and badge overflow #5510
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| Copyright (C) 2023-2026 QuantumNous | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Affero General Public License as | ||
| published by the Free Software Foundation, either version 3 of the | ||
| License, or (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Affero General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Affero General Public License | ||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| For commercial licensing, please contact support@quantumnous.com | ||
| */ | ||
| import * as React from 'react' | ||
| import { cn } from '@/lib/utils' | ||
|
|
||
| type BadgeCellProps = React.HTMLAttributes<HTMLDivElement> | ||
|
|
||
| export function BadgeCell({ className, ...props }: BadgeCellProps) { | ||
| return ( | ||
| <div | ||
| className={cn( | ||
| '-ml-1.5 flex max-w-full min-w-0 items-center gap-1 overflow-hidden [&_[data-slot=status-badge]]:max-w-full [&_[data-slot=status-badge]]:min-w-0', | ||
| className | ||
| )} | ||
| {...props} | ||
| /> | ||
| ) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| /* | ||
| Copyright (C) 2023-2026 QuantumNous | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Affero General Public License as | ||
| published by the Free Software Foundation, either version 3 of the | ||
| License, or (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Affero General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Affero General Public License | ||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| For commercial licensing, please contact support@quantumnous.com | ||
| */ | ||
| import * as React from 'react' | ||
| import { cn } from '@/lib/utils' | ||
| import { | ||
| Tooltip, | ||
| TooltipContent, | ||
| TooltipTrigger, | ||
| } from '@/components/ui/tooltip' | ||
|
|
||
| type TruncatedCellProps = { | ||
| children: React.ReactNode | ||
| cellClassName?: string | ||
| className?: string | ||
| contentClassName?: string | ||
| side?: 'top' | 'bottom' | 'left' | 'right' | ||
| tooltipClassName?: string | ||
| tooltipContent?: React.ReactNode | ||
| } | ||
|
|
||
| export function TruncatedCell({ | ||
| children, | ||
| cellClassName, | ||
| className, | ||
| contentClassName, | ||
| side = 'top', | ||
| tooltipClassName, | ||
| tooltipContent, | ||
| }: TruncatedCellProps) { | ||
| const content = tooltipContent ?? getTextContent(children) | ||
|
|
||
| if (!content) { | ||
| return ( | ||
| <div | ||
| className={cn( | ||
| 'block max-w-full min-w-0 truncate', | ||
| cellClassName, | ||
| className | ||
| )} | ||
| > | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| return ( | ||
| <Tooltip> | ||
| <TooltipTrigger | ||
| render={ | ||
| <div | ||
| className={cn( | ||
| 'block max-w-full min-w-0 truncate', | ||
| cellClassName, | ||
| className | ||
| )} | ||
| /> | ||
| } | ||
| > | ||
| <div className={cn('truncate', contentClassName)}>{children}</div> | ||
| </TooltipTrigger> | ||
| <TooltipContent | ||
| side={side} | ||
| className={cn('max-w-xs break-all', tooltipClassName)} | ||
| > | ||
| {content} | ||
| </TooltipContent> | ||
| </Tooltip> | ||
| ) | ||
| } | ||
|
|
||
| function getTextContent(node: React.ReactNode): string { | ||
| if (typeof node === 'string' || typeof node === 'number') return String(node) | ||
| if (Array.isArray(node)) return node.map(getTextContent).join('') | ||
| return '' | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import { type LucideIcon } from 'lucide-react' | |
| import { stringToColor } from '@/lib/colors' | ||
| import { cn } from '@/lib/utils' | ||
| import { useCopyToClipboard } from '@/hooks/use-copy-to-clipboard' | ||
|
|
||
| export const dotColorMap = { | ||
| success: 'bg-success', | ||
| warning: 'bg-warning', | ||
|
|
@@ -81,7 +82,8 @@ export type StatusBadgeType = 'badge' | 'text' | 'underline' | |
|
|
||
| /** Context that lets ancestor components (e.g. MobileCardList field area) | ||
| * override the badge type without modifying every call site. */ | ||
| export const StatusBadgeTypeContext = React.createContext<StatusBadgeType>('badge') | ||
| export const StatusBadgeTypeContext = | ||
| React.createContext<StatusBadgeType>('badge') | ||
|
|
||
| const sizeMap = { | ||
| sm: 'h-5 gap-1 px-1.5 text-xs leading-none', | ||
|
|
@@ -153,23 +155,29 @@ export function StatusBadge({ | |
| ) : null) | ||
|
|
||
| const isBadge = type === 'badge' | ||
| const title = copyable | ||
| ? `Click to copy: ${copyText || label || ''}` | ||
| : label || undefined | ||
|
Comment on lines
+158
to
+160
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Localize the new title text. On Line 159, Suggested fix import * as React from 'react'
+import { t } from 'i18next'
...
const title = copyable
- ? `Click to copy: ${copyText || label || ''}`
+ ? t('Click to copy: {{value}}', { value: copyText || label || '' })
: label || undefinedAs per coding guidelines, “All user-facing text content must support i18n using the 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
|
|
||
| return ( | ||
| <span | ||
| data-slot='status-badge' | ||
| className={cn( | ||
| 'inline-flex w-fit max-w-full shrink-0 items-center font-medium tracking-normal whitespace-nowrap transition-colors', | ||
| 'inline-flex w-fit max-w-full min-w-0 shrink items-center font-medium tracking-normal whitespace-nowrap transition-colors', | ||
| isBadge | ||
| ? cn('rounded-4xl', sizeMap[size ?? 'sm']) | ||
| : cn(textSizeMap[size ?? 'sm'], type === 'underline' && 'border-b border-current pb-px'), | ||
| : cn( | ||
| textSizeMap[size ?? 'sm'], | ||
| type === 'underline' && 'border-b border-current pb-px' | ||
| ), | ||
| textColorMap[computedVariant], | ||
| pulse && 'animate-pulse', | ||
| copyable && | ||
| 'cursor-copy hover:brightness-95 active:scale-95 dark:hover:brightness-110', | ||
| className | ||
| )} | ||
| onClick={handleClick} | ||
| title={copyable ? `Click to copy: ${copyText || label || ''}` : undefined} | ||
| title={title} | ||
| {...props} | ||
| > | ||
| {showDot && ( | ||
|
|
@@ -221,7 +229,7 @@ export function StatusBadgeList<T>(props: StatusBadgeListProps<T>) { | |
| return ( | ||
| <div | ||
| className={cn( | ||
| 'flex max-w-full items-center gap-1 overflow-hidden', | ||
| 'flex max-w-full min-w-0 items-center gap-1 overflow-hidden', | ||
| className | ||
| )} | ||
| {...domProps} | ||
|
|
||
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.
Handle React element children in text extraction.
On Line 87,
getTextContentskips valid React elements, so<TruncatedCell><span>foo</span></TruncatedCell>won’t derive tooltip text and silently drops the tooltip fallback path.Suggested fix
function getTextContent(node: React.ReactNode): string { if (typeof node === 'string' || typeof node === 'number') return String(node) if (Array.isArray(node)) return node.map(getTextContent).join('') + if (React.isValidElement(node)) return getTextContent(node.props.children) return '' }🤖 Prompt for AI Agents