Skip to content

Commit

Permalink
chore(data-grid): decouple from FAST Foundation (VIV-2022) (#2054)
Browse files Browse the repository at this point in the history
* Remove FoundationElement

* Fix linting

* Decouple from FAST Foundation

---------

Co-authored-by: TaylorJ76 <[email protected]>
  • Loading branch information
RichardHelm and TaylorJ76 authored Dec 11, 2024
1 parent 62cf94d commit 23640b0
Show file tree
Hide file tree
Showing 9 changed files with 1,534 additions and 131 deletions.
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

0 comments on commit 23640b0

Please sign in to comment.