Skip to content

Commit edd7cb5

Browse files
committed
device_name: Prevent focus loss when starting to edit device name.
Adding the input text child conditionally results in creating an input group div around the input element. This results in the browser removing the input element from the DOM and adding a new unfocused one.
1 parent 8d57fab commit edd7cb5

File tree

1 file changed

+6
-6
lines changed
  • software/web/src/modules/device_name

1 file changed

+6
-6
lines changed

software/web/src/modules/device_name/main.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export class DeviceNameStatus extends ConfigComponent<"info/display_name"> {
3939

4040
document.title = API.get("info/display_name").display_name + " - " + __("main.title");
4141

42+
const hide_save = state.display_name == API.get('info/display_name').display_name;
43+
4244
return <StatusSection name="device_name" class="sticky-under-top">
4345
<PageHeader title={__("device_name.status.status")} titleClass="col-4" childrenClass="col-8">
4446
<form onSubmit={(e: Event) => {
@@ -49,12 +51,10 @@ export class DeviceNameStatus extends ConfigComponent<"info/display_name"> {
4951

5052
API.save("info/display_name", state, __("device_name.script.save_failed"));
5153
}}>
52-
<InputText maxLength={32} value={state.display_name} onValue={(v) => this.setState({display_name: v})} required>
53-
{state.display_name == API.get('info/display_name').display_name ? undefined :
54-
<div class="input-group-append">
55-
<Button className="form-control rounded-right" type="submit"><Save/></Button>
56-
</div>
57-
}
54+
<InputText class={hide_save ? "rounded-right" : undefined} maxLength={32} value={state.display_name} onValue={(v) => this.setState({display_name: v})} required>
55+
<div class="input-group-append">
56+
<Button className="form-control rounded-right" type="submit" hidden={hide_save} disabled={hide_save}><Save/></Button>
57+
</div>
5858
</InputText>
5959
</form>
6060
</PageHeader>

0 commit comments

Comments
 (0)