Skip to content

Commit

Permalink
add esc and enter focus out editing
Browse files Browse the repository at this point in the history
  • Loading branch information
plojo committed Sep 11, 2024
1 parent 14f423a commit 074fe6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
21 changes: 11 additions & 10 deletions Distribution/FudgeUserInterface.js

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions Source/UserInterface/CustomElement/CustomTree/CustomTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ namespace FudgeUserInterface {
* Removes the branch of children from this item
*/
private removeBranch(): void {
let content: CustomTreeList<T> = this.getBranch();
if (!content)
let branch: CustomTreeList<T> = this.getBranch();
if (!branch)
return;
this.removeChild(content);
this.removeChild(branch);
}

private create(): void {
Expand Down Expand Up @@ -180,21 +180,23 @@ namespace FudgeUserInterface {

private hndKey = (_event: KeyboardEvent): void => {
_event.stopPropagation();
if (!this.#content.disabled)
return;

let content: CustomTreeList<T> = <CustomTreeList<T>>this.querySelector("ul");
if (!this.#content.disabled) {
if (_event.code == ƒ.KEYBOARD_CODE.ESC || _event.code == ƒ.KEYBOARD_CODE.ENTER)
this.focus();

return;
}

switch (_event.code) {
// TODO: repair arrow key navigation
case ƒ.KEYBOARD_CODE.ARROW_RIGHT:
if (this.hasChildren && !content)
if (this.hasChildren && !this.expanded)
this.expand(true);
else
this.dispatchEvent(new KeyboardEvent(EVENT.FOCUS_NEXT, { bubbles: true, shiftKey: _event.shiftKey, ctrlKey: _event.ctrlKey }));
break;
case ƒ.KEYBOARD_CODE.ARROW_LEFT:
if (content)
if (this.expanded)
this.expand(false);
else
this.dispatchEvent(new KeyboardEvent(EVENT.FOCUS_PREVIOUS, { bubbles: true, shiftKey: _event.shiftKey, ctrlKey: _event.ctrlKey }));
Expand All @@ -211,7 +213,7 @@ namespace FudgeUserInterface {
break;

this.#content.disabled = false;
element?.focus();
element.focus();
break;
case ƒ.KEYBOARD_CODE.SPACE:
this.select(_event.ctrlKey, _event.shiftKey);
Expand Down

0 comments on commit 074fe6e

Please sign in to comment.