Skip to content

Commit 265012f

Browse files
committed
Fix for safari
1 parent 9f29c4b commit 265012f

4 files changed

Lines changed: 53 additions & 10 deletions

File tree

_includes/components/site-search.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
<div class="site-search-overlay" data-site-search-overlay hidden>
1+
<div class="site-search-overlay" data-site-search-overlay hidden aria-hidden="true">
22
<div class="site-search-dialog design-card" role="dialog" aria-modal="true" aria-labelledby="site-search-title">
33
<form class="site-search" data-site-search action="/search/" method="get" role="search">
44
<div class="site-search-bar">
55
<label class="site-search-label" for="site-search-modal-input" id="site-search-title">Search</label>
66
<input
7-
type="search"
7+
type="text"
88
class="design-input site-search-input"
99
name="q"
1010
id="site-search-modal-input"
1111
data-site-search-input
1212
placeholder="Search docs, pricing, encrypt…"
13+
inputmode="search"
14+
enterkeyhint="search"
1315
autocomplete="off"
1416
data-1p-ignore="true"
1517
data-lpignore="true"

assets/css/main.src.css

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2567,6 +2567,7 @@ html.dark .design-link:focus {
25672567
}
25682568

25692569
.design-input {
2570+
-webkit-appearance: none;
25702571
appearance: none;
25712572
background: color-mix(in srgb, var(--design-ink) 4%, var(--design-bg, #fafafa));
25722573
border: 1px solid var(--design-line, var(--design-mid));
@@ -2586,6 +2587,15 @@ html.dark .design-link:focus {
25862587
width: 100%;
25872588
}
25882589

2590+
.design-input::-webkit-search-decoration,
2591+
.design-input::-webkit-search-cancel-button,
2592+
.design-input::-webkit-search-results-button,
2593+
.design-input::-webkit-search-results-decoration {
2594+
-webkit-appearance: none;
2595+
appearance: none;
2596+
display: none;
2597+
}
2598+
25892599
html.dark .design-input,
25902600
html.storm .design-input {
25912601
background-color: color-mix(in srgb, var(--design-ink) 6%, var(--design-bg, #0a0a0a));
@@ -2631,14 +2641,22 @@ html.storm .design-input:focus {
26312641
.site-search-overlay {
26322642
align-items: flex-start;
26332643
background: color-mix(in srgb, var(--design-bg) 72%, transparent);
2634-
display: flex;
2644+
display: none;
26352645
inset: 0;
26362646
justify-content: center;
2647+
left: 0;
26372648
padding: 12vh 1.25rem 2rem;
26382649
position: fixed;
2650+
right: 0;
2651+
top: 0;
2652+
bottom: 0;
26392653
z-index: 130;
26402654
}
26412655

2656+
.site-search-overlay.is-open {
2657+
display: flex;
2658+
}
2659+
26422660
.site-search-overlay[hidden] {
26432661
display: none !important;
26442662
}

assets/js/site-search.js

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
return !!(node.isContentEditable)
112112
}
113113

114+
function isSlashKey(event) {
115+
return event.key === '/' || event.code === 'Slash'
116+
}
117+
114118
function renderPageResults(root, items, query) {
115119
if (!query) {
116120
root.innerHTML = '<p class="design-paragraph">Type to search docs, pricing, and the rest of the site.</p>'
@@ -182,7 +186,7 @@
182186
var lastFocus = null
183187

184188
function isOpen() {
185-
return !overlay.hidden
189+
return overlay.classList.contains('is-open')
186190
}
187191

188192
function runPage(query) {
@@ -211,20 +215,31 @@
211215
nodes[activeIndex].scrollIntoView({ block: 'nearest' })
212216
}
213217

218+
function focusModalInput() {
219+
try {
220+
modalInput.focus()
221+
if (typeof modalInput.select === 'function') modalInput.select()
222+
} catch (_) {}
223+
}
224+
214225
function open() {
215226
lastFocus = document.activeElement
216227
overlay.hidden = false
228+
overlay.classList.add('is-open')
229+
overlay.setAttribute('aria-hidden', 'false')
217230
document.body.classList.add('overflow-hidden')
218-
modalInput.focus()
219-
modalInput.select()
231+
focusModalInput()
232+
window.requestAnimationFrame(focusModalInput)
220233
if (index && modalInput.value) runModal(modalInput.value)
221234
}
222235

223236
function close() {
224237
if (!isOpen()) return
238+
overlay.classList.remove('is-open')
225239
overlay.hidden = true
240+
overlay.setAttribute('aria-hidden', 'true')
226241
document.body.classList.remove('overflow-hidden')
227-
if (lastFocus && typeof lastFocus.focus === 'function') {
242+
if (lastFocus && typeof lastFocus.focus === 'function' && lastFocus !== modalInput) {
228243
try { lastFocus.focus() } catch (_) {}
229244
}
230245
}
@@ -240,6 +255,7 @@
240255
if (pageInput) {
241256
if (initial) pageInput.value = initial
242257
runPage(pageInput.value)
258+
pageInput.focus()
243259
} else if (initial) {
244260
modalInput.value = initial
245261
}
@@ -296,14 +312,14 @@
296312
if (event.target === overlay) close()
297313
})
298314

299-
window.addEventListener('keydown', function (event) {
315+
document.addEventListener('keydown', function (event) {
300316
if (event.key === 'Escape' && isOpen()) {
301317
event.preventDefault()
302318
close()
303319
return
304320
}
305321

306-
if (event.key === '/' && !event.metaKey && !event.ctrlKey && !event.altKey && !isOpen()) {
322+
if (isSlashKey(event) && !event.metaKey && !event.ctrlKey && !event.altKey && !isOpen()) {
307323
if (isTypingTarget(event.target)) return
308324
event.preventDefault()
309325
open()
@@ -319,6 +335,11 @@
319335
event.preventDefault()
320336
setActive(activeIndex - 1)
321337
}
338+
}, true)
339+
340+
modalInput.addEventListener('keypress', function (event) {
341+
if (!isSlashKey(event) || modalInput.value) return
342+
event.preventDefault()
322343
})
323344
})
324345
})()

search/index.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ layout: radar
1818
<form class="site-search-page" data-site-search-page action="/search/" method="get" role="search">
1919
<div class="site-search-page-field">
2020
<input
21-
type="search"
21+
type="text"
2222
class="design-input site-search-input"
2323
name="q"
2424
id="site-search-page-input"
2525
data-site-search-input
2626
placeholder="Search for Claude, pricing, encrypt…"
27+
inputmode="search"
28+
enterkeyhint="search"
2729
autocomplete="off"
2830
autofocus
2931
data-1p-ignore="true"

0 commit comments

Comments
 (0)