about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-02-15 20:15:00 +0100
committerGitHub <noreply@github.com>2025-02-15 20:15:00 +0100
commitdf7002fac041871c3e76f56a4e80e0fead7ae2f6 (patch)
tree9c1ed5b0f7b37625fffe42d14131429d98c0410a
parentf06b75d86d697a52df8d9ac88c4074ee66a40746 (diff)
parent351cc1f5b7d7bee7f9accf75d768e2d179a6f89d (diff)
downloadrust-df7002fac041871c3e76f56a4e80e0fead7ae2f6.tar.gz
rust-df7002fac041871c3e76f56a4e80e0fead7ae2f6.zip
Rollup merge of #137055 - fmease:rustdoc-js-fix-input-placeholder-logic, r=notriddle
rustdoc: Properly restore search input placeholder

Fix the search input placeholder literally getting set to the string *undefined* on blur/defocus.
This was caused by us trying to access an undefined property in the event listener.
To prevent this from regressing again, stop typescript from ignoring the relevant site.

Steps to reproduce the bug fixed in this PR:

1. Focus the search input field by clicking on it and clear the input if necessary
2. Blur/defocus it by clicking somewhere outside of it

---

First bug that would've been caught by TSC if we had had it earlier! Type (quasi-)safety, ahoy! :)
-rw-r--r--src/librustdoc/html/static/js/search.js5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js
index 121a43e3d92..ccbd6811b07 100644
--- a/src/librustdoc/html/static/js/search.js
+++ b/src/librustdoc/html/static/js/search.js
@@ -5318,8 +5318,9 @@ function registerSearchEvents() {
 
     // @ts-expect-error
     searchState.input.addEventListener("blur", () => {
-        // @ts-expect-error
-        searchState.input.placeholder = searchState.input.origPlaceholder;
+        if (window.searchState.input) {
+            window.searchState.input.placeholder = window.searchState.origPlaceholder;
+        }
     });
 
     // Push and pop states are used to add search results to the browser