mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-19 15:26:36 +00:00
Fix copy encryption key (#23515)
This commit is contained in:
parent
d0123b2cce
commit
f3705a7e1d
@ -1,4 +1,4 @@
|
||||
export const copyToClipboard = async (str) => {
|
||||
export const copyToClipboard = async (str, rootEl?: HTMLElement) => {
|
||||
if (navigator.clipboard) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(str);
|
||||
@ -8,10 +8,12 @@ export const copyToClipboard = async (str) => {
|
||||
}
|
||||
}
|
||||
|
||||
const root = rootEl ?? document.body;
|
||||
|
||||
const el = document.createElement("textarea");
|
||||
el.value = str;
|
||||
document.body.appendChild(el);
|
||||
root.appendChild(el);
|
||||
el.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(el);
|
||||
root.removeChild(el);
|
||||
};
|
||||
|
@ -396,7 +396,10 @@ class DialogBackupOnboarding extends LitElement implements HassDialog {
|
||||
}
|
||||
|
||||
private async _copyKeyToClipboard() {
|
||||
await copyToClipboard(this._config!.create_backup.password!);
|
||||
await copyToClipboard(
|
||||
this._config!.create_backup.password!,
|
||||
this.renderRoot.querySelector("div")!
|
||||
);
|
||||
showToast(this, {
|
||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||
});
|
||||
|
@ -206,7 +206,10 @@ class DialogChangeBackupEncryptionKey extends LitElement implements HassDialog {
|
||||
}
|
||||
|
||||
private async _copyKeyToClipboard() {
|
||||
await copyToClipboard(this._newEncryptionKey);
|
||||
await copyToClipboard(
|
||||
this._newEncryptionKey,
|
||||
this.renderRoot.querySelector("div")!
|
||||
);
|
||||
showToast(this, {
|
||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||
});
|
||||
@ -216,7 +219,10 @@ class DialogChangeBackupEncryptionKey extends LitElement implements HassDialog {
|
||||
if (!this._params?.currentKey) {
|
||||
return;
|
||||
}
|
||||
await copyToClipboard(this._params.currentKey);
|
||||
await copyToClipboard(
|
||||
this._params.currentKey,
|
||||
this.renderRoot.querySelector("div")!
|
||||
);
|
||||
showToast(this, {
|
||||
message: this.hass.localize("ui.common.copied_clipboard"),
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user