Skip to content

Commit e90b6bd

Browse files
committed
8350638: Make keyboard navigation more usable in API docs
Reviewed-by: liach, nbenalla
1 parent 4867a4c commit e90b6bd

File tree

21 files changed

+320
-143
lines changed

21 files changed

+320
-143
lines changed

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HelpWriter.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
3636
import jdk.javadoc.internal.html.Content;
3737
import jdk.javadoc.internal.html.ContentBuilder;
38+
import jdk.javadoc.internal.html.Entity;
3839
import jdk.javadoc.internal.html.HtmlId;
3940
import jdk.javadoc.internal.html.HtmlTree;
4041
import jdk.javadoc.internal.html.Text;
@@ -172,6 +173,27 @@ private Content getNavigationSection() {
172173
.add(searchRefer);
173174
navSection.add(section);
174175
}
176+
177+
// Keyboard Navigation
178+
section = newHelpSection(contents.getContent("doclet.help.keyboard_navigation.title"),
179+
HtmlIds.HELP_KEYBOARD_NAVIGATION);
180+
var keyboardPara = HtmlTree.P(contents.getContent("doclet.help.keyboard_navigation.intro"));
181+
var keyboardList = HtmlTree.UL();
182+
if (options.createIndex()) {
183+
keyboardList.add(HtmlTree.LI(contents.getContent("doclet.help.keyboard_navigation.index",
184+
HtmlTree.KBD(Text.of("/")))));
185+
}
186+
keyboardList.add(HtmlTree.LI(contents.getContent("doclet.help.keyboard_navigation.filter",
187+
HtmlTree.KBD(Text.of(".")))));
188+
keyboardList.add(HtmlTree.LI(contents.getContent("doclet.help.keyboard_navigation.escape",
189+
HtmlTree.KBD(Text.of("Esc")))));
190+
keyboardList.add(HtmlTree.LI(contents.getContent("doclet.help.keyboard_navigation.search",
191+
HtmlTree.KBD(Text.of("Tab")), HtmlTree.KBD(Entity.of("downarrow")),
192+
HtmlTree.KBD(Entity.of("uparrow")))));
193+
keyboardList.add(HtmlTree.LI(contents.getContent("doclet.help.keyboard_navigation.tabs",
194+
HtmlTree.KBD(Entity.of("leftarrow")), HtmlTree.KBD(Entity.of("rightarrow")))));
195+
navSection.add(section.add(keyboardPara.add(keyboardList)));
196+
175197
tableOfContents.popNestedList();
176198

177199
return content;

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/HtmlIds.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public class HtmlIds {
9292
static final HtmlId FIELD_SUMMARY = HtmlId.of("field-summary");
9393
static final HtmlId FOR_REMOVAL = HtmlId.of("for-removal");
9494
static final HtmlId HELP_NAVIGATION = HtmlId.of("help-navigation");
95+
static final HtmlId HELP_KEYBOARD_NAVIGATION = HtmlId.of("help-keyboard-navigation");
9596
static final HtmlId HELP_PAGES = HtmlId.of("help-pages");
9697
static final HtmlId HELP_RELEASES = HtmlId.of("help-releases");
9798
static final HtmlId METHOD_DETAIL = HtmlId.of("method-detail");

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/Navigation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ private void addSearch(Content target) {
498498
var inputText = HtmlTree.INPUT(HtmlAttr.InputType.TEXT, HtmlIds.SEARCH_INPUT)
499499
.put(HtmlAttr.PLACEHOLDER, resources.getText("doclet.search_placeholder"))
500500
.put(HtmlAttr.ARIA_LABEL, resources.getText("doclet.search_in_documentation"))
501-
.put(HtmlAttr.AUTOCOMPLETE, "off");
501+
.put(HtmlAttr.AUTOCOMPLETE, "off")
502+
.put(HtmlAttr.SPELLCHECK, "false");
502503
var inputReset = HtmlTree.INPUT(HtmlAttr.InputType.RESET, HtmlIds.RESET_SEARCH)
503504
.put(HtmlAttr.VALUE, resources.getText("doclet.search_reset"));
504505
var searchDiv = HtmlTree.DIV(HtmlStyles.navListSearch)

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/SearchWriter.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
import jdk.javadoc.internal.doclets.toolkit.util.DocPaths;
3333
import jdk.javadoc.internal.html.Content;
3434
import jdk.javadoc.internal.html.ContentBuilder;
35+
import jdk.javadoc.internal.html.Entity;
3536
import jdk.javadoc.internal.html.HtmlAttr;
3637
import jdk.javadoc.internal.html.HtmlId;
3738
import jdk.javadoc.internal.html.HtmlTag;
@@ -85,15 +86,19 @@ protected void addSearchFileContents(Content contentTree) {
8586
.add(HtmlTree.DIV(HtmlTree.INPUT(HtmlAttr.InputType.TEXT, HtmlId.of("page-search-input"))
8687
.put(HtmlAttr.PLACEHOLDER, resources.getText("doclet.search_placeholder"))
8788
.put(HtmlAttr.ARIA_LABEL, resources.getText("doclet.search_in_documentation"))
88-
.put(HtmlAttr.AUTOCOMPLETE, "off"))
89+
.put(HtmlAttr.AUTOCOMPLETE, "off")
90+
.put(HtmlAttr.SPELLCHECK, "false"))
8991
.add(HtmlTree.INPUT(HtmlAttr.InputType.RESET, HtmlId.of("page-search-reset"))
9092
.put(HtmlAttr.VALUE, resources.getText("doclet.search_reset"))
9193
.put(HtmlAttr.STYLE, "margin: 6px;"))
9294
.add(HtmlTree.DETAILS(HtmlStyles.pageSearchDetails)
9395
.add(HtmlTree.SUMMARY(contents.getContent("doclet.search.show_more"))
9496
.setId(HtmlId.of("page-search-expand")))))
9597
.add(HtmlTree.DIV(HtmlStyles.pageSearchInfo, helpSection)
96-
.add(HtmlTree.P(contents.getContent("doclet.search.keyboard_info")))
98+
.add(HtmlTree.P(contents.getContent("doclet.search.keyboard_info",
99+
HtmlTree.KBD(Text.of("Ctrl")), HtmlTree.KBD(Text.of("Cmd")),
100+
new ContentBuilder(HtmlTree.KBD(Entity.of("leftarrow")), Text.of("/"),
101+
HtmlTree.KBD(Entity.of("rightarrow"))))))
97102
.add(HtmlTree.P(contents.getContent("doclet.search.browser_info")))
98103
.add(HtmlTree.SPAN(Text.of("link"))
99104
.setId(HtmlId.of("page-search-link")))

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/TableOfContents.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public class TableOfContents {
4747
*/
4848
public TableOfContents(HtmlDocletWriter writer) {
4949
this.writer = writer;
50-
listBuilder = new ListBuilder(HtmlTree.OL(HtmlStyles.tocList));
50+
listBuilder = new ListBuilder(HtmlTree.OL(HtmlStyles.tocList)
51+
.put(HtmlAttr.TABINDEX, "-1"));
5152
}
5253

5354
/**
@@ -96,18 +97,21 @@ protected Content toContent(boolean hasFilterInput) {
9697
.add(HtmlTree.INPUT(HtmlAttr.InputType.TEXT, HtmlStyles.filterInput)
9798
.put(HtmlAttr.PLACEHOLDER, writer.resources.getText("doclet.filter_label"))
9899
.put(HtmlAttr.ARIA_LABEL, writer.resources.getText("doclet.filter_table_of_contents"))
99-
.put(HtmlAttr.AUTOCOMPLETE, "off"))
100+
.put(HtmlAttr.AUTOCOMPLETE, "off")
101+
.put(HtmlAttr.SPELLCHECK, "false"))
100102
.add(HtmlTree.INPUT(HtmlAttr.InputType.RESET, HtmlStyles.resetFilter)
103+
.put(HtmlAttr.TABINDEX, "-1")
101104
.put(HtmlAttr.VALUE, writer.resources.getText("doclet.filter_reset")));
102105
}
103106
content.add(header);
107+
content.add(listBuilder);
104108
content.add(HtmlTree.BUTTON(HtmlStyles.hideSidebar)
105109
.add(HtmlTree.SPAN(writer.contents.hideSidebar).add(Entity.NO_BREAK_SPACE))
106110
.add(Entity.LEFT_POINTING_ANGLE));
107111
content.add(HtmlTree.BUTTON(HtmlStyles.showSidebar)
108112
.add(Entity.RIGHT_POINTING_ANGLE)
109113
.add(HtmlTree.SPAN(Entity.NO_BREAK_SPACE).add(writer.contents.showSidebar)));
110-
return content.add(listBuilder);
114+
return content;
111115
}
112116

113117
}

0 commit comments

Comments
 (0)