Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export const simulateTextOverflow = (
element: HTMLElement,
scrollWidth: number,
clientWidth: number,
): void => {
// Mock scrollWidth > clientWidth to simulate text overflow
Object.defineProperty(element, 'scrollWidth', { value: scrollWidth, configurable: true });
Object.defineProperty(element, 'clientWidth', { value: clientWidth, configurable: true });
};

export const simulateHoverEvent = (
element: HTMLElement,
options?: MouseEventInit,
): void => {
element.dispatchEvent(new MouseEvent('mousemove', options ?? {
bubbles: true,
cancelable: true,
}));
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {
} from '@jest/globals';
import $ from '@js/core/renderer';

import {
simulateHoverEvent,
simulateTextOverflow,
} from '../../__tests__/__mock__/helpers/dom_utils';
import {
afterTest,
beforeTest,
Expand Down Expand Up @@ -36,4 +40,61 @@ describe('Column Headers', () => {
expect(component.getHeaderCell(0).getAlignment()).toBe('right');
});
});

describe('when cellHintEnabled: true', () => {
it('should show column caption in the tooltip instead of sort index when hovering sort indicator (T1321834)', async () => {
const { component } = await createDataGrid({
dataSource: [{ id: 1, Position: 'Developer', Name: 'John' }],
columns: [
{
dataField: 'Position',
caption: 'Position',
width: 30,
sortOrder: 'asc',
sortIndex: 0,
},
{
dataField: 'Name',
caption: 'Name',
sortOrder: 'desc',
sortIndex: 1,
},
],
sorting: {
mode: 'multiple',
showSortIndexes: true,
},
cellHintEnabled: true,
});

const headerCell = component.getHeaderCell(0);
const headerCellElement = headerCell.getElement() as HTMLElement;

simulateTextOverflow(headerCellElement, 50, 20);
simulateHoverEvent(headerCellElement);

Comment on lines +73 to +75
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test simulates text overflow on the header cell element itself (headerCellElement), but the implementation on line 498 looks for a child element with the class text-content when isHeaderRow is true. The test should simulate overflow on this inner element (the .dx-datagrid-text-content or .dx-treelist-text-content element) to accurately test the new behavior. Currently, the test might not properly validate that the fix works as intended for header cells with the text-content wrapper.

Suggested change
simulateTextOverflow(headerCellElement, 50, 20);
simulateHoverEvent(headerCellElement);
const $headerCell = $(headerCellElement);
const textContentElement = $headerCell
.find('.dx-datagrid-text-content, .dx-treelist-text-content')
.get(0) as HTMLElement | undefined;
const overflowTarget = textContentElement ?? headerCellElement;
simulateTextOverflow(overflowTarget, 50, 20);
simulateHoverEvent(overflowTarget);

Copilot uses AI. Check for mistakes.
expect($(headerCellElement).attr('title')).toBe('Position');
});

it('should show cell text in the tooltip for non-header rows', async () => {
const { instance } = await createDataGrid({
dataSource: [{ id: 1, Position: 'Very Long Position Name That Should Be Truncated' }],
columns: [
{
dataField: 'Position',
caption: 'Position',
width: 50,
},
],
cellHintEnabled: true,
});

const dataCell = instance.getCellElement(0, 0) as HTMLElement;

simulateTextOverflow(dataCell, 200, 50);
simulateHoverEvent(dataCell);

expect($(dataCell).attr('title')).toBe(dataCell.textContent);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const SCROLL_CONTAINER_CLASS = 'scroll-container';
const SCROLLABLE_SIMULATED_CLASS = 'scrollable-simulated';
const GROUP_SPACE_CLASS = 'group-space';
const CONTENT_CLASS = 'content';
const HEADER_TEXT_CONTENT_CLASS = 'text-content';
const TABLE_CLASS = 'table';
const TABLE_FIXED_CLASS = 'table-fixed';
const CONTENT_FIXED_CLASS = 'content-fixed';
Expand Down Expand Up @@ -426,16 +427,7 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
&& !isGroupCellWithTemplate;

if (shouldShowHint) {
if ($element.data(CELL_HINT_VISIBLE)) {
$element.removeAttr('title');
$element.data(CELL_HINT_VISIBLE, false);
}

const difference = $element[0].scrollWidth - $element[0].clientWidth;
if (difference > 0 && !isDefined($element.attr('title'))) {
$element.attr('title', $element.text());
$element.data(CELL_HINT_VISIBLE, true);
}
this._setCellTitleAttribute($cell, isHeaderRow);
}
}));
}
Expand Down Expand Up @@ -493,6 +485,31 @@ export class ColumnsView extends ColumnStateMixin(modules.View) {
return $table;
}

private _setCellTitleAttribute($cell: dxElementWrapper, isHeaderRow: boolean): void {
if ($cell.data(CELL_HINT_VISIBLE)) {
$cell.removeAttr('title');
$cell.data(CELL_HINT_VISIBLE, false);
}

let $cellContent = $cell;
const headerContentClass = this.addWidgetPrefix(HEADER_TEXT_CONTENT_CLASS);

if (isHeaderRow && !$cell.hasClass(headerContentClass)) {
$cellContent = $cell.find(`.${headerContentClass}`);
}

const hasWidthOverflow = $cellContent[0].scrollWidth - $cellContent[0].clientWidth > 0;

if (!hasWidthOverflow || isDefined($cell.attr('title'))) {
return;
}

const hintText = $cellContent.text() || $cell.text();

$cell.attr('title', hintText);
$cell.data(CELL_HINT_VISIBLE, true);
}

/**
* @extended: editing
*/
Expand Down
Loading