@samitouri / QOSami-HFS / commits / 6b4358d3

fix: admin/shared: on mobile, copy-link button was not working

Massimo Melina committed Jan 5, 2026 at 12:09 UTC 6b4358d33c59749d2641121353b9373178c61411
1 file changed +10 -7
shared/index.ts
+10 -7
@@ -211,13 +211,16 @@ export async function copyTextToClipboard(text: string) {
211 }
212 catch {
213 console.debug('fallback clipboard method')
214 - const d = document
215 - const ta = d.createElement("textarea")
216 - ta.textContent = text
217 - d.body.appendChild(ta)
218 - ta.select()
219 - d.execCommand("copy")
220 - d.body.removeChild(ta)
214 + // with this handler we work around the focus-trap of MUI dialogs
215 + const undo = domOn('copy', ev => {
216 + ev.clipboardData?.setData('text/plain', text)
217 + ev.preventDefault()
218 + }, { capture: true, target: document })
219 + try {
220 + if (!document.execCommand('copy'))
221 + throw Error('unknown')
222 + }
223 + finally { undo?.() }
224 }
225 }
226