Skip to content

Commit 19cd510

Browse files
authored
Merge pull request #738 from craftcms/lupe/pt-1071-search-label-is-not-persistent
Add search icon and use in search input, darken border, update shortc…
2 parents fc2816e + 04afa82 commit 19cd510

File tree

12 files changed

+123
-17
lines changed

12 files changed

+123
-17
lines changed

docs/.vuepress/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
docsDir: "docs",
4949
docsBranch: "main",
5050
baseUrl: "https://craftcms.com/docs",
51-
searchPlaceholder: "Search all documentation (Press “/” to focus)",
51+
searchPlaceholder: "Search all documentation",
5252
editLinks: true,
5353
nextLinks: true,
5454
prevLinks: true,

docs/.vuepress/sets/craft-cloud.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
icon: "/docs/icons/icon-cloud.svg",
55
baseDir: "cloud",
66
abandoned: false,
7-
searchPlaceholder: "Search Cloud docs (Press “/” to focus)",
7+
searchPlaceholder: "Search Cloud docs",
88
primarySet: true,
99
globalVars: {
1010
supportEmail: '[email protected]',

docs/.vuepress/sets/craft-cms.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = {
1212
],
1313
defaultVersion: "5.x",
1414
abandoned: false,
15-
searchPlaceholder: "Search the Craft docs (Press “/” to focus)",
15+
searchPlaceholder: "Search the Craft docs",
1616
primarySet: true,
1717
sidebar: {
1818
"5.x": {

docs/.vuepress/sets/craft-commerce.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = {
1313
],
1414
defaultVersion: "5.x",
1515
abandoned: false,
16-
searchPlaceholder: "Search the Commerce docs (Press “/” to focus)",
16+
searchPlaceholder: "Search the Commerce docs",
1717
primarySet: true,
1818
sidebar: {
1919
"5.x": {

docs/.vuepress/sets/craft-nitro.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
defaultVersion: "2.x",
1212
abandoned: true,
1313
deprecationMessage: "Nitro is no longer supported. Please see our <a href=\"https://craftcms.com/blog/retiring-craft-nitro\">announcement</a> and <a href=\"https://craftcms.com/knowledge-base/migrating-from-craft-nitro-to-ddev\">DDEV migration guide</a>.",
14-
searchPlaceholder: "Search the Nitro docs (Press “/” to focus)",
14+
searchPlaceholder: "Search the Nitro docs",
1515
primarySet: false,
1616
sidebar: {
1717
"2.x": {

docs/.vuepress/sets/getting-started-tutorial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = {
44
icon: "/docs/icons/tutorial.svg",
55
baseDir: "getting-started-tutorial",
66
abandoned: false,
7-
searchPlaceholder: "Search the tutorial (Press “/” to focus)",
7+
searchPlaceholder: "Search the tutorial",
88
primarySet: false,
99
sidebar: {
1010
"/": [

docs/.vuepress/theme/components/SearchBox.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<template>
22
<div class="search-box relative w-full">
3+
<SearchIcon />
34
<input
45
ref="input"
56
aria-label="Search"
67
:value="query"
78
:class="{ focused: focused }"
89
:placeholder="placeholder"
9-
class="rounded-md w-full px-5 py-2 text-sm"
10+
class="rounded-md w-full text-sm"
1011
autocomplete="off"
1112
spellcheck="false"
1213
@input="query = $event.target.value"
@@ -83,9 +84,14 @@
8384

8485
<script>
8586
import searchService from "../util/flexsearch-service";
87+
import { getShortcutKey } from '../util/platform';
88+
import SearchIcon from "../icons/SearchIcon.vue";
8689
8790
export default {
8891
name: "SearchBox",
92+
components: {
93+
SearchIcon,
94+
},
8995
data() {
9096
return {
9197
query: "",
@@ -118,12 +124,9 @@ export default {
118124
},
119125
120126
placeholder() {
121-
return (
122-
this.$activeSet.searchPlaceholder ||
123-
this.$site.themeConfig.searchPlaceholder ||
124-
""
125-
);
126-
}
127+
const label = this.$activeSet.searchPlaceholder || this.$site.themeConfig.searchPlaceholder || "";
128+
return `${label} (Press ${getShortcutKey()} + / to focus)`;
129+
},
127130
},
128131
watch: {
129132
query() {
@@ -182,9 +185,11 @@ export default {
182185
},
183186
onHotkey(event) {
184187
// take us to the search input if it doesn’t have focus
188+
// Require Command (metaKey) or Control (ctrlKey) plus '/'
185189
if (
186190
event.srcElement !== this.$refs.input &&
187-
this.hotkeys.includes(event.key)
191+
this.hotkeys.includes(event.key) &&
192+
(event.ctrlKey || event.metaKey)
188193
) {
189194
this.$refs.input.focus();
190195
event.preventDefault();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<template>
2+
<svg
3+
xmlns="http://www.w3.org/2000/svg"
4+
width="23"
5+
height="23"
6+
viewBox="0 0 23 23"
7+
aria-hidden="true">
8+
<g fill="none" fill-rule="evenodd" stroke="currentColor" stroke-width="2" transform="translate(0 -3)">
9+
<circle cx="14" cy="12" r="8" transform="rotate(45 14 12)"/><path d="m8.536 17.464-7.072 7.072"/>
10+
</g>
11+
</svg>
12+
</template>

docs/.vuepress/theme/styles/base.pcss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,33 @@ a {
102102
left: .5em;
103103
}
104104

105+
.search-box {
106+
--input-padding-x: 1.25rem;
107+
--input-padding-y: 0.5rem;
108+
--icon-size: 1rem;
109+
--icon-padding-x: 0.7rem;
110+
--placeholder-color: #5C7194;
111+
112+
input {
113+
border: 1px solid var(--ui-component-color);
114+
padding: var(--input-padding-y) var(--input-padding-x) var(--input-padding-y) calc((var(--icon-padding-x) * 1.5) + var(--icon-size));
115+
116+
&::placeholder {
117+
color: var(--placeholder-color);
118+
}
119+
}
120+
121+
& > svg {
122+
@apply block absolute;
123+
width: var(--icon-size);
124+
height: var(--icon-size);
125+
top: 50%;
126+
left: var(--icon-padding-x);
127+
transform: translateY(-50%);
128+
color: var(--placeholder-color);
129+
}
130+
}
131+
105132
img {
106133
@apply max-w-full;
107134
}

docs/.vuepress/theme/styles/color-mode.pcss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
--code-color-orange: #E96E3A;
4343
--code-color-olive: #778A00;
4444
--code-color-gray: #7C8F00;
45+
46+
.search-box {
47+
--placeholder-color: #91A1BB;
48+
}
4549
}
4650
}
4751

@@ -103,6 +107,8 @@
103107
}
104108

105109
.search-box {
110+
--placeholder-color: #91A1BB;
111+
106112
.suggestions {
107113
@apply bg-gray-900;
108114

0 commit comments

Comments
 (0)