Skip to content

Commit 21c28d7

Browse files
BillLeoutsakosvl346Bill Leoutsakos
andauthored
fix(tables): truncate sort option labels (#6052)
Co-authored-by: Bill Leoutsakos <billleoutsakos@Bills-MacBook-Pro.local>
1 parent 6ff6255 commit 21c28d7

2 files changed

Lines changed: 71 additions & 1 deletion

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { act } from 'react'
5+
import { createRoot, type Root } from 'react-dom/client'
6+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
7+
import { SortDropdown } from '@/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options'
8+
9+
const LONG_COLUMN_LABEL = 'highest_current_champion_role_across_the_entire_company'
10+
11+
function ColumnIcon() {
12+
return <svg data-testid='column-icon' aria-hidden='true' />
13+
}
14+
15+
class ResizeObserverMock {
16+
observe = vi.fn()
17+
unobserve = vi.fn()
18+
disconnect = vi.fn()
19+
}
20+
21+
let container: HTMLDivElement
22+
let root: Root
23+
24+
beforeEach(() => {
25+
vi.stubGlobal('ResizeObserver', ResizeObserverMock)
26+
container = document.createElement('div')
27+
document.body.appendChild(container)
28+
root = createRoot(container)
29+
})
30+
31+
afterEach(() => {
32+
act(() => root.unmount())
33+
container.remove()
34+
vi.unstubAllGlobals()
35+
})
36+
37+
describe('SortDropdown', () => {
38+
it('renders long option labels in the truncatable span between both icons', () => {
39+
act(() => {
40+
root.render(
41+
<SortDropdown
42+
open
43+
onOpenChange={vi.fn()}
44+
config={{
45+
options: [
46+
{
47+
id: 'long-column',
48+
label: LONG_COLUMN_LABEL,
49+
icon: ColumnIcon,
50+
},
51+
],
52+
active: { column: 'long-column', direction: 'asc' },
53+
onSort: vi.fn(),
54+
}}
55+
/>
56+
)
57+
})
58+
59+
const item = document.body.querySelector<HTMLElement>('[role="menuitem"]')
60+
expect(item).not.toBeNull()
61+
expect(item).toHaveAccessibleName(LONG_COLUMN_LABEL)
62+
63+
const label = item?.querySelector('span')
64+
expect(label).not.toBeNull()
65+
expect(label).toHaveTextContent(LONG_COLUMN_LABEL)
66+
expect(label).toHaveClass('min-w-0', 'block', 'truncate')
67+
expect(item?.querySelector('[data-testid="column-icon"]')).not.toBeNull()
68+
expect(item?.querySelectorAll('svg')).toHaveLength(2)
69+
})
70+
})

apps/sim/app/workspace/[workspaceId]/components/resource/components/resource-options/resource-options.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ export const SortDropdown = memo(function SortDropdown({
287287
}}
288288
>
289289
{Icon && <Icon />}
290-
{option.label}
290+
<FloatingOverflowText label={option.label} className='block truncate' />
291291
{DirectionIcon && (
292292
<DirectionIcon className='ml-auto size-[12px] text-[var(--text-tertiary)]' />
293293
)}

0 commit comments

Comments
 (0)