diff --git a/src/nodeElement/folderElement.ts b/src/nodeElement/folderElement.ts index aa9b4e32..6e51596e 100644 --- a/src/nodeElement/folderElement.ts +++ b/src/nodeElement/folderElement.ts @@ -14,19 +14,19 @@ class FolderElement extends NodeElement { private triggerEvent: TriggerEvent; constructor({ - $treeElement, closedIconElement, getScrollLeft, node, openedIconElement, tabIndex, + treeElement, triggerEvent, }: FolderElementParams) { super({ - $treeElement, getScrollLeft, node, tabIndex, + treeElement, }); this.closedIconElement = closedIconElement; diff --git a/src/nodeElement/index.ts b/src/nodeElement/index.ts index 5c275bcd..52ca1c35 100644 --- a/src/nodeElement/index.ts +++ b/src/nodeElement/index.ts @@ -6,28 +6,28 @@ import BorderDropHint from "./borderDropHint"; import GhostDropHint from "./ghostDropHint"; export interface NodeElementParams { - $treeElement: JQuery; getScrollLeft: GetScrollLeft; node: Node; tabIndex?: number; + treeElement: HTMLElement; } class NodeElement { - private $treeElement: JQuery; private getScrollLeft: GetScrollLeft; private tabIndex?: number; + private treeElement: HTMLElement; public element: HTMLElement; public node: Node; constructor({ - $treeElement, getScrollLeft, node, tabIndex, + treeElement, }: NodeElementParams) { this.getScrollLeft = getScrollLeft; this.tabIndex = tabIndex; - this.$treeElement = $treeElement; + this.treeElement = treeElement; this.init(node); } @@ -68,16 +68,10 @@ class NodeElement { this.node = node; if (!node.element) { - const element = this.$treeElement.get(0); - - if (element) { - node.element = element; - } + node.element = this.treeElement; } - if (node.element) { - this.element = node.element; - } + this.element = node.element; } public select(mustSetFocus: boolean): void { diff --git a/src/test/nodeElement/borderDropHint.test.ts b/src/test/nodeElement/borderDropHint.test.ts new file mode 100644 index 00000000..5c6088a6 --- /dev/null +++ b/src/test/nodeElement/borderDropHint.test.ts @@ -0,0 +1,22 @@ +import BorderDropHint from "../../nodeElement/borderDropHint"; + +it("creates an element", () => { + const element = document.createElement("div"); + + const jqTreeElement = document.createElement("div"); + jqTreeElement.classList.add("jqtree-element"); + element.append(jqTreeElement); + + new BorderDropHint(element, 0); + + expect(jqTreeElement.children.length).toBe(1); + expect(jqTreeElement.children[0]).toHaveClass("jqtree-border"); +}); + +it("doesn't create an element if the node doesn't have a jqtree-element child", () => { + const element = document.createElement("div"); + + new BorderDropHint(element, 0); + + expect(element.children).toBeEmpty(); +}); diff --git a/src/test/nodeElement/index.test.ts b/src/test/nodeElement/index.test.ts new file mode 100644 index 00000000..a2eddf67 --- /dev/null +++ b/src/test/nodeElement/index.test.ts @@ -0,0 +1,29 @@ +import { Node } from "../../node"; +import NodeElement from "../../nodeElement"; + +it("sets the element to the element of the node", () => { + const treeElement = document.createElement("div"); + document.body.append(treeElement); + + const element = document.createElement("div"); + document.body.append(element); + + const node = new Node(); + node.element = element; + + const getScrollLeft = () => 0; + + const nodeElement = new NodeElement({ getScrollLeft, node, treeElement }); + expect(nodeElement.element).toEqual(element); +}); + +it("sets the element to the tree element when the node doesn't have an element", () => { + const treeElement = document.createElement("div"); + document.body.append(treeElement); + + const node = new Node(); + const getScrollLeft = () => 0; + + const nodeElement = new NodeElement({ getScrollLeft, node, treeElement }); + expect(nodeElement.element).toEqual(treeElement); +}); diff --git a/src/tree.jquery.ts b/src/tree.jquery.ts index 135687a7..e040b802 100644 --- a/src/tree.jquery.ts +++ b/src/tree.jquery.ts @@ -250,16 +250,16 @@ export class JqTreeWidget extends SimpleWidget { ); const openedIconElement = this.renderer.openedIconElement; const tabIndex = this.options.tabIndex; - const $treeElement = this.element; + const treeElement = this.element.get(0) as HTMLElement; const triggerEvent = this.triggerEvent.bind(this); return new FolderElement({ - $treeElement, closedIconElement, getScrollLeft, node, openedIconElement, tabIndex, + treeElement, triggerEvent, }); } @@ -269,13 +269,13 @@ export class JqTreeWidget extends SimpleWidget { this.scrollHandler, ); const tabIndex = this.options.tabIndex; - const $treeElement = this.element; + const treeElement = this.element.get(0) as HTMLElement; return new NodeElement({ - $treeElement, getScrollLeft, node, tabIndex, + treeElement, }); }