Table: Add title attribute to make truncated headings legible (#115155)

* fix(table): add HTML title attribute to make truncated headings legible

* fix(table): avoid redundant display name calculation

Co-authored-by: Paul Marbach <paul.marbach@grafana.com>

---------

Co-authored-by: Paul Marbach <paul.marbach@grafana.com>
This commit is contained in:
Jesse David Peterson
2025-12-11 12:22:10 -04:00
committed by GitHub
co-authored by Paul Marbach
parent 5bda17be3f
commit 5dcfc19060
2 changed files with 16 additions and 1 deletions
@@ -451,6 +451,19 @@ describe('TableNG', () => {
expect(screen.getByText('A1')).toBeInTheDocument();
expect(screen.getByText('1')).toBeInTheDocument();
});
it('shows full column name in title attribute for truncated headers', () => {
const { container } = render(
<TableNG enableVirtualization={false} data={createBasicDataFrame()} width={800} height={600} />
);
const headers = container.querySelectorAll('[role="columnheader"]');
const firstHeaderSpan = headers[0].querySelector('span');
const secondHeaderSpan = headers[1].querySelector('span');
expect(firstHeaderSpan).toHaveAttribute('title', 'Column A');
expect(secondHeaderSpan).toHaveAttribute('title', 'Column B');
});
});
describe('Footer options', () => {
@@ -55,7 +55,9 @@ const HeaderCell: React.FC<HeaderCellProps> = ({
{showTypeIcons && (
<Icon className={styles.headerCellIcon} name={getFieldTypeIcon(field)} title={field?.type} size="sm" />
)}
<span className={styles.headerCellLabel}>{getDisplayName(field)}</span>
<span className={styles.headerCellLabel} title={displayName}>
{displayName}
</span>
{direction && (
<Icon
className={cx(styles.headerCellIcon, styles.headerSortIcon)}