Skip to content

Commit cdf8930

Browse files
committed
8274625: Search field placeholder behavior
Reviewed-by: prappo
1 parent df125f6 commit cdf8930

File tree

9 files changed

+23
-37
lines changed

9 files changed

+23
-37
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public class Navigation {
7676
private Content userHeader;
7777
private final String rowListTitle;
7878
private final Content searchLabel;
79+
private final String searchPlaceholder;
7980
private SubNavLinks subNavLinks;
8081

8182
public enum PageMode {
@@ -131,6 +132,7 @@ public Navigation(Element element, HtmlConfiguration configuration, PageMode pag
131132
this.links = new Links(path);
132133
this.rowListTitle = configuration.getDocResources().getText("doclet.Navigation");
133134
this.searchLabel = contents.getContent("doclet.search");
135+
this.searchPlaceholder = configuration.getDocResources().getText("doclet.search_placeholder");
134136
}
135137

136138
public Navigation setNavLinkModule(Content navLinkModule) {
@@ -595,10 +597,11 @@ private void addHelpLink(Content tree) {
595597
}
596598

597599
private void addSearch(Content tree) {
598-
String search = "search";
599600
String reset = "reset";
600-
HtmlTree inputText = HtmlTree.INPUT("text", HtmlIds.SEARCH_INPUT, search);
601-
HtmlTree inputReset = HtmlTree.INPUT(reset, HtmlIds.RESET_BUTTON, reset);
601+
HtmlTree inputText = HtmlTree.INPUT("text", HtmlIds.SEARCH_INPUT)
602+
.put(HtmlAttr.PLACEHOLDER, searchPlaceholder);
603+
HtmlTree inputReset = HtmlTree.INPUT(reset, HtmlIds.RESET_BUTTON)
604+
.put(HtmlAttr.VALUE, reset);
602605
HtmlTree searchDiv = HtmlTree.DIV(HtmlStyle.navListSearch,
603606
HtmlTree.LABEL(HtmlIds.SEARCH_INPUT.name(), searchLabel));
604607
searchDiv.add(inputText);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2010, 2021, 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
@@ -57,6 +57,7 @@ public enum HtmlAttr {
5757
ONCLICK,
5858
ONKEYDOWN,
5959
ONLOAD,
60+
PLACEHOLDER,
6061
REL,
6162
ROLE,
6263
ROWS,

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,20 +520,18 @@ public static HtmlTree HTML(String lang, Content head, Content body) {
520520
}
521521

522522
/**
523-
* Creates an HTML {@code INPUT} element with the given id and initial value.
523+
* Creates an HTML {@code INPUT} element with the given id.
524524
* The element as marked as initially disabled.
525525
*
526526
* @param type the type of input
527527
* @param id the id
528-
* @param value the initial value
529528
* @return the element
530529
*/
531-
public static HtmlTree INPUT(String type, HtmlId id, String value) {
530+
public static HtmlTree INPUT(String type, HtmlId id) {
532531
return new HtmlTree(TagName.INPUT)
533532
.put(HtmlAttr.TYPE, type)
534533
.setId(id)
535-
.put(HtmlAttr.VALUE, value)
536-
.put(HtmlAttr.DISABLED, "disabled");
534+
.put(HtmlAttr.DISABLED, "");
537535
}
538536

539537
/**

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/formats/html/resources/search.js.template

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, 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
@@ -96,28 +96,16 @@ function createMatcher(pattern, flags) {
9696
var isCamelCase = /[A-Z]/.test(pattern);
9797
return new RegExp(pattern, flags + (isCamelCase ? "" : "i"));
9898
}
99-
var watermark = 'Search';
10099
$(function() {
101100
var search = $("#search-input");
102101
var reset = $("#reset-button");
103102
search.val('');
104103
search.prop("disabled", false);
105104
reset.prop("disabled", false);
106-
search.val(watermark).addClass('watermark');
107-
search.blur(function() {
108-
if ($(this).val().length === 0) {
109-
$(this).val(watermark).addClass('watermark');
110-
}
111-
});
112-
search.on('click keydown paste', function() {
113-
if ($(this).val() === watermark) {
114-
$(this).val('').removeClass('watermark');
115-
}
116-
});
117105
reset.click(function() {
118106
search.val('').focus();
119107
});
120-
search.focus()[0].setSelectionRange(0, 0);
108+
search.focus();
121109
});
122110
$.widget("custom.catcomplete", $.ui.autocomplete, {
123111
_create: function() {

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/doclets.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ doclet.Type=Type
223223
doclet.Modifier_and_Type=Modifier and Type
224224
doclet.Implementation=Implementation(s):
225225
doclet.search=SEARCH:
226+
doclet.search_placeholder=Search
226227
doclet.Field=Field
227228
doclet.Property=Property
228229
doclet.Constructor=Constructor

src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/resources/stylesheet.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -617,8 +617,9 @@ ul.ui-autocomplete li {
617617
top:10px;
618618
font-size:0;
619619
}
620-
.watermark {
621-
color:#545454;
620+
::placeholder {
621+
color:#909090;
622+
opacity: 1;
622623
}
623624
.search-tag-desc-result {
624625
font-style:italic;

test/langtools/jdk/javadoc/doclet/checkStylesheetClasses/CheckStylesheetClasses.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ void run() throws Exception {
137137
// used in search.js; may be worth documenting in HtmlStyle
138138
removeAll(styleSheetNames, "result-highlight", "result-item",
139139
"search-tag-desc-result", "search-tag-holder-result",
140-
"ui-autocomplete", "ui-autocomplete-category",
141-
"watermark", "expanded");
140+
"ui-autocomplete", "ui-autocomplete-category", "expanded");
142141

143142
// snippet-related
144143
removeAll(styleSheetNames, "bold", "highlighted", "italic");

test/langtools/jdk/javadoc/doclet/testSearch/TestSearch.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ void checkSearchOutput(String fileName, boolean expectedOutput, boolean moduleDi
421421
"<div class=\"nav-list-search\">",
422422
"""
423423
<label for="search-input">SEARCH:</label>
424-
<input type="text" id="search-input" value="search" disabled="disabled">
425-
<input type="reset" id="reset-button" value="reset" disabled="disabled">
424+
<input type="text" id="search-input" disabled placeholder="Search">
425+
<input type="reset" id="reset-button" disabled value="reset">
426426
""");
427427
checkOutput(fileName, true,
428428
"<div class=\"flex-box\">");
@@ -710,12 +710,6 @@ void checkSearchJS() {
710710

711711
checkOutput("search.js", true,
712712
"function searchIndexWithMatcher(indexArray, matcher, category, nameFunc) {",
713-
"""
714-
search.on('click keydown paste', function() {
715-
if ($(this).val() === watermark) {
716-
$(this).val('').removeClass('watermark');
717-
}
718-
});""",
719713
"""
720714
function getURLPrefix(ui) {
721715
var urlPrefix="";

test/langtools/jdk/javadoc/doclet/testStylesheet/TestStylesheet.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ public void test(Path base) {
191191
font-size:0;
192192
}""",
193193
"""
194-
.watermark {
195-
color:#545454;
194+
::placeholder {
195+
color:#909090;
196+
opacity: 1;
196197
}""");
197198

198199
checkOutput("pkg/A.html", true,

0 commit comments

Comments
 (0)