Dialog focus (#1472)

* focus on dialog controls when is open

* fix "Configure and Upload" label

* fix focus on user fields
This commit is contained in:
Alberto Iannaccone 2022-09-29 15:16:28 +02:00 committed by GitHub
parent d6cb23f782
commit 6f07717369
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 14 deletions

View File

@ -600,7 +600,7 @@ export class BoardsServiceProvider
boardsConfig.selectedBoard && boardsConfig.selectedBoard &&
availableBoards.every(({ selected }) => !selected) availableBoards.every(({ selected }) => !selected)
) { ) {
let port = boardsConfig.selectedPort let port = boardsConfig.selectedPort;
// If the selected board has the same port of an unknown board // If the selected board has the same port of an unknown board
// that is already in availableBoards we might get a duplicate port. // that is already in availableBoards we might get a duplicate port.
// So we remove the one already in the array and add the selected one. // So we remove the one already in the array and add the selected one.
@ -611,7 +611,7 @@ export class BoardsServiceProvider
// get the "Unknown board port" that we will substitute, // get the "Unknown board port" that we will substitute,
// then we can include it in the "availableBoard object" // then we can include it in the "availableBoard object"
// pushed below; to ensure addressLabel is included // pushed below; to ensure addressLabel is included
port = availableBoards[found].port port = availableBoards[found].port;
availableBoards.splice(found, 1); availableBoards.splice(found, 1);
} }
availableBoards.push({ availableBoards.push({

View File

@ -229,7 +229,7 @@ export namespace UploadSketch {
id: 'arduino-upload-with-configuration-sketch', id: 'arduino-upload-with-configuration-sketch',
label: nls.localize( label: nls.localize(
'arduino/sketch/configureAndUpload', 'arduino/sketch/configureAndUpload',
'Configure And Upload' 'Configure and Upload'
), ),
category: 'Arduino', category: 'Arduino',
}; };

View File

@ -58,7 +58,7 @@ export class UserFields extends Contribution {
} }
} }
private selectedFqbnAddress(): string | undefined { private selectedFqbnAddress(): string | undefined {
const { boardsConfig } = this.boardsServiceProvider; const { boardsConfig } = this.boardsServiceProvider;
const fqbn = boardsConfig.selectedBoard?.fqbn; const fqbn = boardsConfig.selectedBoard?.fqbn;
if (!fqbn) { if (!fqbn) {
@ -78,7 +78,9 @@ export class UserFields extends Contribution {
): Promise<BoardUserField[] | undefined> { ): Promise<BoardUserField[] | undefined> {
const cached = this.cachedUserFields.get(key); const cached = this.cachedUserFields.get(key);
// Deep clone the array of board fields to avoid editing the cached ones // Deep clone the array of board fields to avoid editing the cached ones
this.userFieldsDialog.value = cached ? cached.slice() : await this.boardsServiceProvider.selectedBoardUserFields(); this.userFieldsDialog.value = cached
? cached.slice()
: await this.boardsServiceProvider.selectedBoardUserFields();
const result = await this.userFieldsDialog.open(); const result = await this.userFieldsDialog.open();
if (!result) { if (!result) {
return; return;
@ -140,10 +142,7 @@ export class UserFields extends Contribution {
} }
notifyFailedWithError(e: Error): void { notifyFailedWithError(e: Error): void {
if ( if (this.boardRequiresUserFields && CoreError.UploadFailed.is(e)) {
this.boardRequiresUserFields &&
CoreError.UploadFailed.is(e)
) {
this.userFieldsSet = false; this.userFieldsSet = false;
} }
} }

View File

@ -171,6 +171,9 @@ export class UploadCertificateDialog extends AbstractDialog<void> {
Widget.detach(this.widget); Widget.detach(this.widget);
} }
Widget.attach(this.widget, this.contentNode); Widget.attach(this.widget, this.contentNode);
const firstButton = this.widget.node.querySelector('button');
firstButton?.focus();
this.widget.busyCallback = this.busyCallback.bind(this); this.widget.busyCallback = this.busyCallback.bind(this);
super.onAfterAttach(msg); super.onAfterAttach(msg);
this.update(); this.update();

View File

@ -115,6 +115,8 @@ export class UploadFirmwareDialog extends AbstractDialog<void> {
Widget.detach(this.widget); Widget.detach(this.widget);
} }
Widget.attach(this.widget, this.contentNode); Widget.attach(this.widget, this.contentNode);
const firstButton = this.widget.node.querySelector('button');
firstButton?.focus();
this.widget.busyCallback = this.busyCallback.bind(this); this.widget.busyCallback = this.busyCallback.bind(this);
super.onAfterAttach(msg); super.onAfterAttach(msg);
this.update(); this.update();

View File

@ -16,9 +16,9 @@ export const UserFieldsComponent = ({
const [boardUserFields, setBoardUserFields] = React.useState< const [boardUserFields, setBoardUserFields] = React.useState<
BoardUserField[] BoardUserField[]
>(initialBoardUserFields); >(initialBoardUserFields);
const [uploadButtonDisabled, setUploadButtonDisabled] = const [uploadButtonDisabled, setUploadButtonDisabled] =
React.useState<boolean>(true); React.useState<boolean>(true);
const firstInputElement = React.useRef<HTMLInputElement>(null);
React.useEffect(() => { React.useEffect(() => {
setBoardUserFields(initialBoardUserFields); setBoardUserFields(initialBoardUserFields);
@ -48,7 +48,10 @@ export const UserFieldsComponent = ({
React.useEffect(() => { React.useEffect(() => {
updateUserFields(boardUserFields); updateUserFields(boardUserFields);
setUploadButtonDisabled(!allFieldsHaveValues(boardUserFields)); setUploadButtonDisabled(!allFieldsHaveValues(boardUserFields));
}, [boardUserFields]); if (firstInputElement.current) {
firstInputElement.current.focus();
}
}, [boardUserFields, updateUserFields]);
return ( return (
<div> <div>
@ -71,6 +74,7 @@ export const UserFieldsComponent = ({
field.label field.label
)} )}
onChange={updateUserField(index)} onChange={updateUserField(index)}
ref={index === 0 ? firstInputElement : undefined}
/> />
</div> </div>
</div> </div>

View File

@ -13,7 +13,7 @@ import { BoardUserField } from '../../../common/protocol';
@injectable() @injectable()
export class UserFieldsDialogWidget extends ReactWidget { export class UserFieldsDialogWidget extends ReactWidget {
protected _currentUserFields: BoardUserField[] = []; private _currentUserFields: BoardUserField[] = [];
constructor(private cancel: () => void, private accept: () => Promise<void>) { constructor(private cancel: () => void, private accept: () => Promise<void>) {
super(); super();
@ -34,7 +34,7 @@ export class UserFieldsDialogWidget extends ReactWidget {
}); });
} }
protected setUserFields(userFields: BoardUserField[]): void { private setUserFields(userFields: BoardUserField[]): void {
this._currentUserFields = userFields; this._currentUserFields = userFields;
} }

View File

@ -376,7 +376,7 @@
"cantOpen": "A folder named \"{0}\" already exists. Can't open sketch.", "cantOpen": "A folder named \"{0}\" already exists. Can't open sketch.",
"close": "Are you sure you want to close the sketch?", "close": "Are you sure you want to close the sketch?",
"compile": "Compiling sketch...", "compile": "Compiling sketch...",
"configureAndUpload": "Configure And Upload", "configureAndUpload": "Configure and Upload",
"createdArchive": "Created archive '{0}'.", "createdArchive": "Created archive '{0}'.",
"doneCompiling": "Done compiling.", "doneCompiling": "Done compiling.",
"doneUploading": "Done uploading.", "doneUploading": "Done uploading.",