From cd85e329edee3ac5b196f29c4bd65c763340a347 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Fri, 24 Mar 2023 10:42:17 +0100 Subject: [PATCH] fix: the focus in the sketchbook widget Ref: arduino/arduino-ide#1720 Signed-off-by: Akos Kitta --- .../browser/library/library-list-widget.ts | 13 +------ .../src/browser/utils/dom.ts | 37 +++++++++++++++++++ .../sketchbook-composite-widget.tsx | 11 ++++-- .../widgets/sketchbook/sketchbook-widget.tsx | 8 +--- 4 files changed, 47 insertions(+), 22 deletions(-) create mode 100644 arduino-ide-extension/src/browser/utils/dom.ts diff --git a/arduino-ide-extension/src/browser/library/library-list-widget.ts b/arduino-ide-extension/src/browser/library/library-list-widget.ts index 050783816..25480de95 100644 --- a/arduino-ide-extension/src/browser/library/library-list-widget.ts +++ b/arduino-ide-extension/src/browser/library/library-list-widget.ts @@ -20,6 +20,7 @@ import { Installable } from '../../common/protocol'; import { ListItemRenderer } from '../widgets/component-list/list-item-renderer'; import { nls } from '@theia/core/lib/common'; import { LibraryFilterRenderer } from '../widgets/component-list/filter-renderer'; +import { findChildTheiaButton } from '../utils/dom'; @injectable() export class LibraryListWidget extends ListWidget< @@ -243,17 +244,7 @@ class MessageBoxDialog extends AbstractDialog { protected override onAfterAttach(message: Message): void { super.onAfterAttach(message); - let buttonToFocus: HTMLButtonElement | undefined = undefined; - for (const child of Array.from(this.controlPanel.children)) { - if (child instanceof HTMLButtonElement) { - if (child.classList.contains('main')) { - buttonToFocus = child; - break; - } - buttonToFocus = child; - } - } - buttonToFocus?.focus(); + findChildTheiaButton(this.controlPanel)?.focus(); } } export namespace MessageBoxDialog { diff --git a/arduino-ide-extension/src/browser/utils/dom.ts b/arduino-ide-extension/src/browser/utils/dom.ts new file mode 100644 index 000000000..5d6e65d3c --- /dev/null +++ b/arduino-ide-extension/src/browser/utils/dom.ts @@ -0,0 +1,37 @@ +import { notEmpty } from '@theia/core'; + +/** + * Finds the closest child HTMLButtonElement representing a Theia button. + * A button is a Theia button if it's a `