Skip to content
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

chore(data-grid): decouple from FAST Foundation (VIV-2022) #2054

Merged
merged 4 commits into from
Dec 11, 2024
Merged
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
63 changes: 46 additions & 17 deletions libs/components/src/lib/data-grid/data-grid-cell.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,32 +182,45 @@ describe('vwc-data-grid-cell', () => {
expect(hasActiveClassBeforeFocus).toBeFalsy();
expect(baseElement?.classList.contains('active')).toBeTruthy();
});

it('should ignore additional focusin events', async () => {
const spy = jest.fn();
element.addEventListener('cell-focused', spy);

element.dispatchEvent(new Event('focusin'));
element.dispatchEvent(new Event('focusin'));

expect(spy).toHaveBeenCalledTimes(1);
});
});

describe('handleKeydown', () => {
it('should focus on target element with enter key', async () => {
element.cellType = 'default';
element.columnDefinition = {
columnDataKey: 'name',
cellFocusTargetCallback: () => {
return elementToFocus;
},
cellInternalFocusQueue: true,
};
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }));
expect(document.activeElement).toEqual(elementToFocus);
});
it.each(['Enter', 'F2'])(
'should focus on target element with %s key',
async (key) => {
element.cellType = 'default';
element.columnDefinition = {
columnDataKey: 'name',
cellFocusTargetCallback: () => {
return elementToFocus;
},
cellInternalFocusQueue: true,
};
element.dispatchEvent(new KeyboardEvent('keydown', { key }));
expect(document.activeElement).toEqual(elementToFocus);
}
);

it('should focus on target element with F2 key', async () => {
element.cellType = 'default';
it('should focus on header target element when cellType is columnheader', async () => {
element.cellType = 'columnheader';
element.columnDefinition = {
columnDataKey: 'name',
cellFocusTargetCallback: () => {
headerCellFocusTargetCallback: () => {
return elementToFocus;
},
cellInternalFocusQueue: true,
headerCellInternalFocusQueue: true,
};
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'F2' }));
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }));
expect(document.activeElement).toEqual(elementToFocus);
});

Expand All @@ -222,6 +235,22 @@ describe('vwc-data-grid-cell', () => {
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
expect(document.activeElement).toEqual(element);
});

it('should not move focus if a child is already focused', async () => {
element.cellType = 'default';
element.columnDefinition = {
columnDataKey: 'name',
cellFocusTargetCallback: () => {
return elementToFocus;
},
cellInternalFocusQueue: true,
};
const focusedChild = document.createElement('input');
element.appendChild(focusedChild);
focusedChild.focus();
element.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter' }));
expect(document.activeElement).toBe(focusedChild);
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { VividElementDefinitionContext } from '../../shared/design-system/d
import { DataGridCellRole, DataGridCellSortStates } from './data-grid.options';
import type { DataGridCell } from './data-grid-cell';

function shouldShowSortIcons<T extends DataGridCell>(x: T): boolean {
function shouldShowSortIcons(x: DataGridCell): boolean {
if (x.columnDefinition) {
x.ariaSort = !x.columnDefinition.sortable
? null
Expand Down
Loading
Loading