2024-08-23 14:45:28 +00:00
|
|
|
import { UINode } from "./node";
|
|
|
|
|
|
|
|
export class Container extends UINode {
|
|
|
|
public children: UINode[];
|
|
|
|
protected containerElement: HTMLDivElement;
|
|
|
|
private focused: number = 0;
|
|
|
|
|
|
|
|
public constructor(title: string) {
|
|
|
|
super(title);
|
|
|
|
this.children = [];
|
|
|
|
this.containerElement = document.createElement("div");
|
|
|
|
this.containerElement.setAttribute("tabindex", "-1");
|
|
|
|
this.focused = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public focus() {
|
|
|
|
this.containerElement.focus();
|
2024-08-24 18:23:10 +00:00
|
|
|
return this;
|
2024-08-23 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public _onFocus() {
|
|
|
|
this.children[this.focused].focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
public add(node: UINode) {
|
|
|
|
this.children.push(node);
|
|
|
|
node._onConnect();
|
|
|
|
this.containerElement.appendChild(node.render());
|
2024-08-30 14:33:06 +00:00
|
|
|
return this;
|
2024-08-23 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public remove(node: UINode) {
|
|
|
|
this.children.splice(this.children.indexOf(node), 1);
|
|
|
|
node._onDisconnect();
|
|
|
|
this.containerElement.removeChild(node.render());
|
2024-08-30 14:33:06 +00:00
|
|
|
return this;
|
2024-08-23 14:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
|
|
|
return this.containerElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getChildren(): UINode[] {
|
|
|
|
return this.children;
|
|
|
|
}
|
|
|
|
|
|
|
|
public getElement() {
|
|
|
|
return this.containerElement;
|
|
|
|
}
|
|
|
|
|
2024-08-24 18:23:10 +00:00
|
|
|
public setAriaLabel(text: string) {
|
2024-08-23 14:45:28 +00:00
|
|
|
this.containerElement.setAttribute("aria-label", text);
|
2024-08-24 18:23:10 +00:00
|
|
|
return this;
|
2024-08-23 14:45:28 +00:00
|
|
|
}
|
|
|
|
}
|