Skip to content

Commit 6f07717

Browse files
author
Alberto Iannaccone
authored
Dialog focus (#1472)
* focus on dialog controls when is open * fix "Configure and Upload" label * fix focus on user fields
1 parent d6cb23f commit 6f07717

File tree

8 files changed

+22
-14
lines changed

8 files changed

+22
-14
lines changed

Diff for: arduino-ide-extension/src/browser/boards/boards-service-provider.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ export class BoardsServiceProvider
600600
boardsConfig.selectedBoard &&
601601
availableBoards.every(({ selected }) => !selected)
602602
) {
603-
let port = boardsConfig.selectedPort
603+
let port = boardsConfig.selectedPort;
604604
// If the selected board has the same port of an unknown board
605605
// that is already in availableBoards we might get a duplicate port.
606606
// So we remove the one already in the array and add the selected one.
@@ -611,7 +611,7 @@ export class BoardsServiceProvider
611611
// get the "Unknown board port" that we will substitute,
612612
// then we can include it in the "availableBoard object"
613613
// pushed below; to ensure addressLabel is included
614-
port = availableBoards[found].port
614+
port = availableBoards[found].port;
615615
availableBoards.splice(found, 1);
616616
}
617617
availableBoards.push({

Diff for: arduino-ide-extension/src/browser/contributions/upload-sketch.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export namespace UploadSketch {
229229
id: 'arduino-upload-with-configuration-sketch',
230230
label: nls.localize(
231231
'arduino/sketch/configureAndUpload',
232-
'Configure And Upload'
232+
'Configure and Upload'
233233
),
234234
category: 'Arduino',
235235
};

Diff for: arduino-ide-extension/src/browser/contributions/user-fields.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class UserFields extends Contribution {
5858
}
5959
}
6060

61-
private selectedFqbnAddress(): string | undefined {
61+
private selectedFqbnAddress(): string | undefined {
6262
const { boardsConfig } = this.boardsServiceProvider;
6363
const fqbn = boardsConfig.selectedBoard?.fqbn;
6464
if (!fqbn) {
@@ -78,7 +78,9 @@ export class UserFields extends Contribution {
7878
): Promise<BoardUserField[] | undefined> {
7979
const cached = this.cachedUserFields.get(key);
8080
// Deep clone the array of board fields to avoid editing the cached ones
81-
this.userFieldsDialog.value = cached ? cached.slice() : await this.boardsServiceProvider.selectedBoardUserFields();
81+
this.userFieldsDialog.value = cached
82+
? cached.slice()
83+
: await this.boardsServiceProvider.selectedBoardUserFields();
8284
const result = await this.userFieldsDialog.open();
8385
if (!result) {
8486
return;
@@ -140,10 +142,7 @@ export class UserFields extends Contribution {
140142
}
141143

142144
notifyFailedWithError(e: Error): void {
143-
if (
144-
this.boardRequiresUserFields &&
145-
CoreError.UploadFailed.is(e)
146-
) {
145+
if (this.boardRequiresUserFields && CoreError.UploadFailed.is(e)) {
147146
this.userFieldsSet = false;
148147
}
149148
}

Diff for: arduino-ide-extension/src/browser/dialogs/certificate-uploader/certificate-uploader-dialog.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ export class UploadCertificateDialog extends AbstractDialog<void> {
171171
Widget.detach(this.widget);
172172
}
173173
Widget.attach(this.widget, this.contentNode);
174+
const firstButton = this.widget.node.querySelector('button');
175+
firstButton?.focus();
176+
174177
this.widget.busyCallback = this.busyCallback.bind(this);
175178
super.onAfterAttach(msg);
176179
this.update();

Diff for: arduino-ide-extension/src/browser/dialogs/firmware-uploader/firmware-uploader-dialog.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ export class UploadFirmwareDialog extends AbstractDialog<void> {
115115
Widget.detach(this.widget);
116116
}
117117
Widget.attach(this.widget, this.contentNode);
118+
const firstButton = this.widget.node.querySelector('button');
119+
firstButton?.focus();
118120
this.widget.busyCallback = this.busyCallback.bind(this);
119121
super.onAfterAttach(msg);
120122
this.update();

Diff for: arduino-ide-extension/src/browser/dialogs/user-fields/user-fields-component.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ export const UserFieldsComponent = ({
1616
const [boardUserFields, setBoardUserFields] = React.useState<
1717
BoardUserField[]
1818
>(initialBoardUserFields);
19-
2019
const [uploadButtonDisabled, setUploadButtonDisabled] =
2120
React.useState<boolean>(true);
21+
const firstInputElement = React.useRef<HTMLInputElement>(null);
2222

2323
React.useEffect(() => {
2424
setBoardUserFields(initialBoardUserFields);
@@ -48,7 +48,10 @@ export const UserFieldsComponent = ({
4848
React.useEffect(() => {
4949
updateUserFields(boardUserFields);
5050
setUploadButtonDisabled(!allFieldsHaveValues(boardUserFields));
51-
}, [boardUserFields]);
51+
if (firstInputElement.current) {
52+
firstInputElement.current.focus();
53+
}
54+
}, [boardUserFields, updateUserFields]);
5255

5356
return (
5457
<div>
@@ -71,6 +74,7 @@ export const UserFieldsComponent = ({
7174
field.label
7275
)}
7376
onChange={updateUserField(index)}
77+
ref={index === 0 ? firstInputElement : undefined}
7478
/>
7579
</div>
7680
</div>

Diff for: arduino-ide-extension/src/browser/dialogs/user-fields/user-fields-dialog.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { BoardUserField } from '../../../common/protocol';
1313

1414
@injectable()
1515
export class UserFieldsDialogWidget extends ReactWidget {
16-
protected _currentUserFields: BoardUserField[] = [];
16+
private _currentUserFields: BoardUserField[] = [];
1717

1818
constructor(private cancel: () => void, private accept: () => Promise<void>) {
1919
super();
@@ -34,7 +34,7 @@ export class UserFieldsDialogWidget extends ReactWidget {
3434
});
3535
}
3636

37-
protected setUserFields(userFields: BoardUserField[]): void {
37+
private setUserFields(userFields: BoardUserField[]): void {
3838
this._currentUserFields = userFields;
3939
}
4040

Diff for: i18n/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@
376376
"cantOpen": "A folder named \"{0}\" already exists. Can't open sketch.",
377377
"close": "Are you sure you want to close the sketch?",
378378
"compile": "Compiling sketch...",
379-
"configureAndUpload": "Configure And Upload",
379+
"configureAndUpload": "Configure and Upload",
380380
"createdArchive": "Created archive '{0}'.",
381381
"doneCompiling": "Done compiling.",
382382
"doneUploading": "Done uploading.",

0 commit comments

Comments
 (0)