Skip to content

Commit 761dea4

Browse files
committed
Header: Merge search forms into a single form
Still with two input elements though, due to the different placeholders
1 parent b19b0fb commit 761dea4

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

.template-lintrc.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
module.exports = {
44
extends: ['octane', 'a11y'],
5-
6-
pending: [{ moduleId: 'app/components/header', only: ['no-duplicate-landmark-elements'] }],
75
};

app/components/header.hbs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<h1>crates.io</h1>
66
</LinkTo>
77

8-
<form local-class="desktop-search-form" action='/search' role="search" {{on "submit" (prevent-default this.search)}} data-test-search-form>
8+
<form local-class="search-form" action='/search' role="search" {{on "submit" (prevent-default this.search)}} data-test-search-form>
99
{{! template-lint-disable require-input-label}}
1010
{{! disabled due to https://github.com/ember-template-lint/ember-template-lint/issues/2141 }}
1111
<input
1212
type="text"
13-
local-class="search"
13+
local-class="search-input-lg"
1414
name="q"
1515
id="cargo-desktop-search"
1616
placeholder="Click or press 'S' to search..."
@@ -24,6 +24,23 @@
2424
aria-label="Search"
2525
data-test-search-input
2626
>
27+
28+
{{! Second input fields for narrow screens because CSS does not allow us to change the placeholder }}
29+
<input
30+
type="text"
31+
local-class="search-input-sm"
32+
name="q"
33+
placeholder="Search"
34+
value={{this.header.searchValue}}
35+
oninput={{this.updateSearchValue}}
36+
autocorrect="off"
37+
required
38+
aria-label="Search"
39+
>
40+
41+
{{! Hidden submit button to enable enter-to-submit behavior for form with multiple inputs }}
42+
<button type="submit" local-class="submit-button">Submit</button>
43+
2744
{{on-key 's' (focus '#cargo-desktop-search')}}
2845
{{on-key 'S' (focus '#cargo-desktop-search')}}
2946
{{on-key 'shift+s' (focus '#cargo-desktop-search')}}
@@ -144,19 +161,5 @@
144161
</dd.Menu>
145162
</Dropdown>
146163
</div>
147-
148-
<form local-class='mobile-search' action='/search' role="search" {{on "submit" (prevent-default this.search)}}>
149-
<input
150-
type="text"
151-
local-class="search"
152-
name="q"
153-
placeholder="Search"
154-
value={{this.header.searchValue}}
155-
oninput={{this.updateSearchValue}}
156-
autocorrect="off"
157-
required
158-
aria-label="Search"
159-
>
160-
</form>
161164
</div>
162165
</header>

app/components/header.module.css

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,12 @@
5050
margin-right: 10px;
5151
}
5252

53-
.desktop-search-form {
53+
.search-form {
5454
grid-area: search;
5555
display: flex;
56-
flex-grow: 1;
57-
58-
@media only screen and (max-width: 820px) {
59-
display: none;
60-
}
6156
}
6257

63-
input.search {
58+
.search-input {
6459
font-size: 90%;
6560
border: none;
6661
color: black;
@@ -83,20 +78,28 @@ input.search {
8378
}
8479
}
8580

86-
.mobile-search {
87-
display: none;
88-
grid-area: search;
89-
margin: 0 10px 10px;
81+
.search-input-lg {
82+
composes: search-input;
9083

91-
input.search {
92-
margin: 0;
84+
@media only screen and (max-width: 820px) {
85+
display: none;
9386
}
87+
}
88+
89+
.search-input-sm {
90+
composes: search-input;
91+
display: none;
92+
margin: 0 10px 10px;
9493

9594
@media only screen and (max-width: 820px) {
96-
display: block;
95+
display: unset;
9796
}
9897
}
9998

99+
.submit-button {
100+
display: none;
101+
}
102+
100103
.sep {
101104
margin: 0 10px;
102105
color: var(--separator-color);

0 commit comments

Comments
 (0)