Skip to content

Commit 9483e9b

Browse files
Handle blur on theme buttons nicely
1 parent 8c80124 commit 9483e9b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/librustdoc/html/render.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ fn write_shared(cx: &Context,
789789
format!(
790790
r#"var themes = document.getElementById("theme-choices");
791791
var themePicker = document.getElementById("theme-picker");
792-
themePicker.onclick = function() {{
792+
793+
function switchThemeButtonState() {{
793794
if (themes.style.display === "block") {{
794795
themes.style.display = "none";
795796
themePicker.style.borderBottomRightRadius = "3px";
@@ -800,12 +801,29 @@ themePicker.onclick = function() {{
800801
themePicker.style.borderBottomLeftRadius = "0";
801802
}}
802803
}};
804+
805+
function handleThemeButtonsBlur(e) {{
806+
var active = document.activeElement;
807+
var related = e.relatedTarget;
808+
809+
if (active.id !== "themePicker" &&
810+
(!active.parentNode || active.parentNode.id !== "theme-choices") &&
811+
(!related ||
812+
(related.id !== "themePicker" &&
813+
(!related.parentNode || related.parentNode.id !== "theme-choices")))) {{
814+
switchThemeButtonState();
815+
}}
816+
}}
817+
818+
themePicker.onclick = switchThemeButtonState;
819+
themePicker.onblur = handleThemeButtonsBlur;
803820
[{}].forEach(function(item) {{
804821
var but = document.createElement('button');
805822
but.innerHTML = item;
806823
but.onclick = function(el) {{
807824
switchTheme(currentTheme, mainTheme, item);
808825
}};
826+
but.onblur = handleThemeButtonsBlur;
809827
themes.appendChild(but);
810828
}});"#,
811829
themes.iter()

0 commit comments

Comments
 (0)