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

refactor: svgNodeFilter #6661

Merged
merged 1 commit into from
Feb 8, 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
13 changes: 7 additions & 6 deletions projects/cdk/constants/svg-node-filter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Filtering SVGElements for TreeWalker
// Filter must be a function in IE, other modern browsers are compliant to this format
export const svgNodeFilter: NodeFilter = ((node: Node) =>
'ownerSVGElement' in node
? NodeFilter.FILTER_REJECT
: NodeFilter.FILTER_ACCEPT) as any;
export const svgNodeFilter: Exclude<NodeFilter, (node: Node) => number> = {
acceptNode(node: Node): number {
return 'ownerSVGElement' in node
? NodeFilter.FILTER_REJECT
: NodeFilter.FILTER_ACCEPT;
},
};
13 changes: 6 additions & 7 deletions projects/cdk/constants/test/svg-node-filter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import {svgNodeFilter} from '@taiga-ui/cdk';

// TODO: 3.0 rewrite tests after IE removing
describe('SvgNodeFilter', () => {
it('child SVG', () => {
const node: Node = {ownerSVGElement: null} as unknown as Node;

expect((svgNodeFilter as any)(node)).toBe(NodeFilter.FILTER_REJECT);
expect(svgNodeFilter.acceptNode({ownerSVGElement: null} as unknown as Node)).toBe(
NodeFilter.FILTER_REJECT,
);
});

it('not child SVG', () => {
const node: Node = {} as unknown as Node;

expect((svgNodeFilter as any)(node)).toBe(NodeFilter.FILTER_ACCEPT);
expect(svgNodeFilter.acceptNode({} as unknown as Node)).toBe(
NodeFilter.FILTER_ACCEPT,
);
});
});
Loading