Skip to content

Dialog focus #1472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ export class BoardsServiceProvider
boardsConfig.selectedBoard &&
availableBoards.every(({ selected }) => !selected)
) {
let port = boardsConfig.selectedPort
let port = boardsConfig.selectedPort;
// If the selected board has the same port of an unknown board
// 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.
Expand All @@ -611,7 +611,7 @@ export class BoardsServiceProvider
// get the "Unknown board port" that we will substitute,
// then we can include it in the "availableBoard object"
// pushed below; to ensure addressLabel is included
port = availableBoards[found].port
port = availableBoards[found].port;
availableBoards.splice(found, 1);
}
availableBoards.push({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export namespace UploadSketch {
id: 'arduino-upload-with-configuration-sketch',
label: nls.localize(
'arduino/sketch/configureAndUpload',
'Configure And Upload'
'Configure and Upload'
),
category: 'Arduino',
};
Expand Down
11 changes: 5 additions & 6 deletions arduino-ide-extension/src/browser/contributions/user-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class UserFields extends Contribution {
}
}

private selectedFqbnAddress(): string | undefined {
private selectedFqbnAddress(): string | undefined {
const { boardsConfig } = this.boardsServiceProvider;
const fqbn = boardsConfig.selectedBoard?.fqbn;
if (!fqbn) {
Expand All @@ -78,7 +78,9 @@ export class UserFields extends Contribution {
): Promise<BoardUserField[] | undefined> {
const cached = this.cachedUserFields.get(key);
// 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();
if (!result) {
return;
Expand Down Expand Up @@ -140,10 +142,7 @@ export class UserFields extends Contribution {
}

notifyFailedWithError(e: Error): void {
if (
this.boardRequiresUserFields &&
CoreError.UploadFailed.is(e)
) {
if (this.boardRequiresUserFields && CoreError.UploadFailed.is(e)) {
this.userFieldsSet = false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export class UploadCertificateDialog extends AbstractDialog<void> {
Widget.detach(this.widget);
}
Widget.attach(this.widget, this.contentNode);
const firstButton = this.widget.node.querySelector('button');
firstButton?.focus();

this.widget.busyCallback = this.busyCallback.bind(this);
super.onAfterAttach(msg);
this.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ export class UploadFirmwareDialog extends AbstractDialog<void> {
Widget.detach(this.widget);
}
Widget.attach(this.widget, this.contentNode);
const firstButton = this.widget.node.querySelector('button');
firstButton?.focus();
this.widget.busyCallback = this.busyCallback.bind(this);
super.onAfterAttach(msg);
this.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export const UserFieldsComponent = ({
const [boardUserFields, setBoardUserFields] = React.useState<
BoardUserField[]
>(initialBoardUserFields);

const [uploadButtonDisabled, setUploadButtonDisabled] =
React.useState<boolean>(true);
const firstInputElement = React.useRef<HTMLInputElement>(null);

React.useEffect(() => {
setBoardUserFields(initialBoardUserFields);
Expand Down Expand Up @@ -48,7 +48,10 @@ export const UserFieldsComponent = ({
React.useEffect(() => {
updateUserFields(boardUserFields);
setUploadButtonDisabled(!allFieldsHaveValues(boardUserFields));
}, [boardUserFields]);
if (firstInputElement.current) {
firstInputElement.current.focus();
}
}, [boardUserFields, updateUserFields]);

return (
<div>
Expand All @@ -71,6 +74,7 @@ export const UserFieldsComponent = ({
field.label
)}
onChange={updateUserField(index)}
ref={index === 0 ? firstInputElement : undefined}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BoardUserField } from '../../../common/protocol';

@injectable()
export class UserFieldsDialogWidget extends ReactWidget {
protected _currentUserFields: BoardUserField[] = [];
private _currentUserFields: BoardUserField[] = [];

constructor(private cancel: () => void, private accept: () => Promise<void>) {
super();
Expand All @@ -34,7 +34,7 @@ export class UserFieldsDialogWidget extends ReactWidget {
});
}

protected setUserFields(userFields: BoardUserField[]): void {
private setUserFields(userFields: BoardUserField[]): void {
this._currentUserFields = userFields;
}

Expand Down
2 changes: 1 addition & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
"cantOpen": "A folder named \"{0}\" already exists. Can't open sketch.",
"close": "Are you sure you want to close the sketch?",
"compile": "Compiling sketch...",
"configureAndUpload": "Configure And Upload",
"configureAndUpload": "Configure and Upload",
"createdArchive": "Created archive '{0}'.",
"doneCompiling": "Done compiling.",
"doneUploading": "Done uploading.",
Expand Down