-
Notifications
You must be signed in to change notification settings - Fork 2
/
SearchFocus.html
82 lines (72 loc) · 2.04 KB
/
SearchFocus.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<!--
Codepen sample: https://codepen.io/kellyhutchins/pen/XWPMajM
-->
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1,maximum-scale=1,user-scalable=no"
/>
<title>Search Popup Focus</title>
<link
rel="stylesheet"
href="https://js.arcgis.com/4.26/esri/themes/light/main.css"
/>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<script src="https://js.arcgis.com/4.26/"></script>
<script>
require(["esri/Map", "esri/views/SceneView", "esri/core/reactiveUtils", "esri/widgets/Search"], (
Map,
SceneView,
reactiveUtils,
Search
) => {
const map = new Map({
basemap: "satellite",
ground: "world-elevation"
});
const view = new SceneView({
scale: 123456789,
container: "viewDiv",
map
});
const search = new Search({
view
});
// Add the search widget to the top right corner of the view
view.ui.add(search, {
position: "top-right"
});
search.on("search-complete", () => onSearchComplete());
// Add the search widget to the top right corner of the view
view.ui.add(search, {
position: "top-right"
});
let abortController = null;
async function onSearchComplete() {
abortController?.abort();
const { signal } = (abortController = new AbortController());
// When the popup is visible set focus on it.
await reactiveUtils.whenOnce(() => view.popup.visible, signal);
view.popup.focus();
// And when the popup is closed move the focus back to the search wiget.
await reactiveUtils.whenOnce(() => !view.popup.visible, signal);
search.focus();
}
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>