From 670a78b3a78ef341da7cdcafde58923a66b82ff9 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 31 Aug 2024 17:26:54 +0200 Subject: [PATCH] Fix code examples buttons not appearing on click on mobile --- src/librustdoc/html/static/js/main.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/html/static/js/main.js b/src/librustdoc/html/static/js/main.js index 75f2a1418cd..c3e219f2c87 100644 --- a/src/librustdoc/html/static/js/main.js +++ b/src/librustdoc/html/static/js/main.js @@ -1878,9 +1878,15 @@ href="https://doc.rust-lang.org/${channel}/rustdoc/read-documentation/search.htm if (elem === null) { return; } - const buttons = elem.querySelector(".button-holder"); + let buttons = elem.querySelector(".button-holder"); if (buttons === null) { - return; + // On mobile, you can't hover an element so buttons need to be created on click + // if they're not already there. + addCopyButton(event); + buttons = elem.querySelector(".button-holder"); + if (buttons === null) { + return; + } } buttons.classList.toggle("keep-visible"); }