Skip to content

Commit

Permalink
feat: support pressing escape (#38)
Browse files Browse the repository at this point in the history
This should be an ongoing effort, since new pages will require this
support to be implemented, but this PR implements for the existing
pages.
  • Loading branch information
eh-am authored Jan 11, 2024
1 parent 6f37319 commit 215f698
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/components/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ function setupCardKeydown(
} else if (keyPressed === "ArrowDown") {
e.preventDefault();
onVerticalMovement(allCards, card, keyPressed);
} else if (keyPressed === "Escape") {
hideChannelActions(card);
card.focus();
}
}

Expand All @@ -122,6 +125,13 @@ function getChannelActionsWrapper(card: HTMLElement) {
);
}

function hideChannelActions(card: HTMLElement) {
const channelActionsWrapper = getChannelActionsWrapper(card);
channelActionsWrapper.forEach((el) => {
el.style.opacity = "0";
});
}

export function handleFocusOut(card: HTMLElement): Teardown {
function onFocusOut(e: FocusEvent) {
const target = e.relatedTarget as HTMLElement | null;
Expand All @@ -130,10 +140,7 @@ export function handleFocusOut(card: HTMLElement): Teardown {
}

if (!card.contains(target)) {
const channelActionsWrapper = getChannelActionsWrapper(card);
channelActionsWrapper.forEach((el) => {
el.style.opacity = "0";
});
hideChannelActions(card);
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/sections/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ function setupUserMenuKeydown(): Teardown {
} else {
n.value.focus();
}
} else if (keyPressed === "Escape") {
if (userButton) {
findClickableUserButtonEl(userButton)?.click();
focusBackWhenTransitionEnds(userButton);
}
}
}

Expand Down

0 comments on commit 215f698

Please sign in to comment.