Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/table-utils-node-import.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frontify/fondue-components": patch
---

fix(Table): read the DOM element classes when a row click is checked, so the package imports in Node
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* (c) Copyright Frontify Ltd., all rights reserved. */

// @vitest-environment node

import { describe, expect, it } from 'vitest';

import { shouldIgnoreRowClick } from '../utils';

describe('Table utils without a DOM', () => {
it('loads in Node and ignores no row click without an event', () => {
expect(shouldIgnoreRowClick()).toBe(false);
});
});
8 changes: 6 additions & 2 deletions packages/components/src/components/Table/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export function handleKeyDown(event: KeyboardEvent<HTMLTableElement>) {
}
}

const INTERACTIVE_ELEMENTS_LIST = [HTMLButtonElement, HTMLAnchorElement, HTMLInputElement];
const INTERACTIVE_ROLES_LIST = ['button', 'link'];

export function shouldIgnoreRowClick(event?: MouseEvent): boolean {
Expand All @@ -48,7 +47,12 @@ export function shouldIgnoreRowClick(event?: MouseEvent): boolean {
}

while (element && !(element instanceof HTMLTableRowElement)) {
if (INTERACTIVE_ELEMENTS_LIST.some((interactiveElement) => element instanceof interactiveElement)) {
// Read at call time, since the DOM classes do not exist when the module loads in Node.
if (
[HTMLButtonElement, HTMLAnchorElement, HTMLInputElement].some(
(interactiveElement) => element instanceof interactiveElement,
)
) {
return true;
}

Expand Down
Loading