radar-sdk-js 4.3.1-beta.2 → 4.3.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -56,7 +56,7 @@ Radar.initialize('prj_test_pk_...', { /* options */ });
56
56
 
57
57
  Add the following script in your `html` file
58
58
  ```html
59
- <script src="https://js.radar.com/v4.3.1-beta.2/radar.min.js"></script>
59
+ <script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
60
60
  ```
61
61
 
62
62
  Then initialize the Radar SDK
@@ -73,8 +73,8 @@ To create a map, first initialize the Radar SDK with your publishable key. Then
73
73
  ```html
74
74
  <html>
75
75
  <head>
76
- <link href="https://js.radar.com/v4.3.1-beta.2/radar.css" rel="stylesheet">
77
- <script src="https://js.radar.com/v4.3.1-beta.2/radar.min.js"></script>
76
+ <link href="https://js.radar.com/v4.3.2-beta.0/radar.css" rel="stylesheet">
77
+ <script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
78
78
  </head>
79
79
 
80
80
  <body>
@@ -98,8 +98,8 @@ To create an autocomplete input, first initialize the Radar SDK with your publis
98
98
  ```html
99
99
  <html>
100
100
  <head>
101
- <link href="https://js.radar.com/v4.3.1-beta.2/radar.css" rel="stylesheet">
102
- <script src="https://js.radar.com/v4.3.1-beta.2/radar.min.js"></script>
101
+ <link href="https://js.radar.com/v4.3.2-beta.0/radar.css" rel="stylesheet">
102
+ <script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
103
103
  </head>
104
104
 
105
105
  <body>
@@ -130,8 +130,8 @@ To power [geofencing](https://radar.com/documentation/geofencing/overview) exper
130
130
  ```html
131
131
  <html>
132
132
  <head>
133
- <link href="https://js.radar.com/v4.3.1-beta.2/radar.css" rel="stylesheet">
134
- <script src="https://js.radar.com/v4.3.1-beta.2/radar.min.js"></script>
133
+ <link href="https://js.radar.com/v4.3.2-beta.0/radar.css" rel="stylesheet">
134
+ <script src="https://js.radar.com/v4.3.2-beta.0/radar.min.js"></script>
135
135
  </head>
136
136
 
137
137
  <body>
package/dist/core.d.ts ADDED
@@ -0,0 +1,32 @@
1
+ import type { Location, RadarAutocompleteParams, RadarConversionParams, RadarDistanceParams, RadarForwardGeocodeParams, RadarMatrixParams, RadarMetadata, RadarOptions, RadarReverseGeocodeParams, RadarSearchGeofencesParams, RadarSearchPlacesParams, RadarTrackParams, RadarTripOptions, RadarValidateAddressParams } from './types';
2
+ import '../styles/radar.css';
3
+ declare class Radar {
4
+ static get VERSION(): string;
5
+ static initialize(publishableKey: string, options?: RadarOptions): void;
6
+ static clear(): void;
7
+ static setUserId(userId?: string): void;
8
+ static setDescription(description?: string): void;
9
+ static setMetadata(metadata?: RadarMetadata): void;
10
+ static getLocation(): Promise<import("./types").NavigatorPosition>;
11
+ static trackOnce(params?: RadarTrackParams): Promise<import("./types").RadarTrackResponse>;
12
+ static trackVerified(params?: RadarTrackParams): Promise<import("./types").RadarTrackVerifiedResponse>;
13
+ static getContext(params: Location): Promise<import("./types").RadarContextResponse>;
14
+ static setTripOptions(tripOptions?: RadarTripOptions): void;
15
+ static clearTripOptions(): void;
16
+ static getTripOptions(): RadarTripOptions;
17
+ static startTrip(tripOptions: RadarTripOptions): Promise<import("./types").RadarTripResponse>;
18
+ static updateTrip(tripOptions: RadarTripOptions): Promise<import("./types").RadarTripResponse>;
19
+ static completeTrip(): Promise<import("./types").RadarTripResponse>;
20
+ static cancelTrip(): Promise<import("./types").RadarTripResponse>;
21
+ static logConversion(params: RadarConversionParams): Promise<import("./types").RadarConversionResponse>;
22
+ static forwardGeocode(params: RadarForwardGeocodeParams): Promise<import("./types").RadarGeocodeResponse>;
23
+ static reverseGeocode(params: RadarReverseGeocodeParams): Promise<import("./types").RadarGeocodeResponse>;
24
+ static ipGeocode(): Promise<import("./types").RadarIPGeocodeResponse>;
25
+ static autocomplete(params: RadarAutocompleteParams): Promise<import("./types").RadarAutocompleteResponse>;
26
+ static searchGeofences(params: RadarSearchGeofencesParams): Promise<import("./types").RadarSearchGeofencesResponse>;
27
+ static searchPlaces(params: RadarSearchPlacesParams): Promise<import("./types").RadarSearchPlacesResponse>;
28
+ static validateAddress(params: RadarValidateAddressParams): Promise<import("./types").RadarValidateAddressResponse>;
29
+ static distance(params: RadarDistanceParams): Promise<import("./types").RadarRouteResponse>;
30
+ static matrix(params: RadarMatrixParams): Promise<import("./types").RadarMatrixResponse>;
31
+ }
32
+ export default Radar;
package/dist/radar.js CHANGED
@@ -405,7 +405,7 @@ class Navigator {
405
405
  }
406
406
  }
407
407
 
408
- var SDK_VERSION = '4.3.1-beta.2';
408
+ var SDK_VERSION = '4.3.2-beta.0';
409
409
 
410
410
  class Http {
411
411
  static request({ method, path, data, host, version, headers = {}, responseType, }) {
@@ -1730,6 +1730,9 @@ const CLASSNAMES = {
1730
1730
  POWERED_BY_RADAR: 'radar-powered',
1731
1731
  NO_RESULTS: 'radar-no-results',
1732
1732
  };
1733
+ const ARIA = {
1734
+ EXPANDED: 'aria-expanded',
1735
+ };
1733
1736
  const defaultAutocompleteOptions = {
1734
1737
  container: 'autocomplete',
1735
1738
  debounceMS: 200,
@@ -1820,10 +1823,6 @@ class AutocompleteUI {
1820
1823
  // result list element
1821
1824
  this.resultsList = document.createElement('ul');
1822
1825
  this.resultsList.classList.add(CLASSNAMES.RESULTS_LIST);
1823
- this.resultsList.classList.add('id', CLASSNAMES.RESULTS_LIST);
1824
- this.resultsList.setAttribute('role', 'listbox');
1825
- this.resultsList.setAttribute('aria-live', 'polite');
1826
- this.resultsList.setAttribute('aria-label', 'Search results');
1827
1826
  setHeight(this.resultsList, this.config);
1828
1827
  if (containerEL.nodeName === 'INPUT') {
1829
1828
  // if an <input> element is provided, use that as the inputField,
@@ -1850,13 +1849,6 @@ class AutocompleteUI {
1850
1849
  this.wrapper.appendChild(searchIcon);
1851
1850
  this.container.appendChild(this.wrapper);
1852
1851
  }
1853
- // set aria roles
1854
- this.inputField.setAttribute('role', 'combobox');
1855
- this.inputField.setAttribute('aria-controls', CLASSNAMES.RESULTS_LIST);
1856
- this.inputField.setAttribute('aria-expanded', 'false');
1857
- this.inputField.setAttribute('aria-haspopup', 'listbox');
1858
- this.inputField.setAttribute('aria-autocomplete', 'list');
1859
- this.inputField.setAttribute('aria-activedescendant', '');
1860
1852
  // setup event listeners
1861
1853
  this.inputField.addEventListener('input', this.handleInput.bind(this));
1862
1854
  this.inputField.addEventListener('keydown', this.handleKeyboardNavigation.bind(this));
@@ -1950,8 +1942,6 @@ class AutocompleteUI {
1950
1942
  results.forEach((result, index) => {
1951
1943
  const li = document.createElement('li');
1952
1944
  li.classList.add(CLASSNAMES.RESULTS_ITEM);
1953
- li.setAttribute('role', 'option');
1954
- li.setAttribute('id', `item-${index}`);
1955
1945
  // construct result with bolded label
1956
1946
  let listContent;
1957
1947
  if (result.formattedAddress.includes(result.addressLabel) && result.layer !== 'postalCode') {
@@ -2003,7 +1993,7 @@ class AutocompleteUI {
2003
1993
  if (this.isOpen) {
2004
1994
  return;
2005
1995
  }
2006
- this.inputField.setAttribute('aria-expanded', 'true');
1996
+ this.wrapper.setAttribute(ARIA.EXPANDED, 'true');
2007
1997
  this.resultsList.removeAttribute('hidden');
2008
1998
  this.isOpen = true;
2009
1999
  }
@@ -2015,8 +2005,7 @@ class AutocompleteUI {
2015
2005
  // (add 100ms delay if closed from link click)
2016
2006
  const linkClick = e && (e.relatedTarget === this.poweredByLink);
2017
2007
  setTimeout(() => {
2018
- this.inputField.setAttribute('aria-expanded', 'false');
2019
- this.inputField.setAttribute('aria-activedescendant', '');
2008
+ this.wrapper.removeAttribute(ARIA.EXPANDED);
2020
2009
  this.resultsList.setAttribute('hidden', '');
2021
2010
  this.highlightedIndex = -1;
2022
2011
  this.isOpen = false;
@@ -2041,34 +2030,37 @@ class AutocompleteUI {
2041
2030
  }
2042
2031
  // add class name to newly highlighted item
2043
2032
  resultItems[index].classList.add(CLASSNAMES.SELECTED_ITEM);
2044
- // set aria active descendant
2045
- this.inputField.setAttribute('aria-activedescendant', `item-${index}`);
2046
2033
  this.highlightedIndex = index;
2047
2034
  }
2048
2035
  handleKeyboardNavigation(event) {
2049
- const key = event.key;
2036
+ // fallback to deprecated "keyCode" if event.code not set
2037
+ const code = event.code !== undefined ? event.code : event.keyCode;
2050
2038
  // allow event to propagate if result list is not open
2051
2039
  if (!this.isOpen) {
2052
2040
  return;
2053
2041
  }
2054
- switch (key) {
2042
+ switch (code) {
2055
2043
  // Next item
2056
2044
  case 'Tab':
2057
2045
  case 'ArrowDown':
2046
+ case 40:
2058
2047
  event.preventDefault();
2059
2048
  this.goTo(this.highlightedIndex + 1);
2060
2049
  break;
2061
2050
  // Prev item
2062
2051
  case 'ArrowUp':
2052
+ case 38:
2063
2053
  event.preventDefault();
2064
2054
  this.goTo(this.highlightedIndex - 1);
2065
2055
  break;
2066
2056
  // Select
2067
2057
  case 'Enter':
2058
+ case 13:
2068
2059
  this.select(this.highlightedIndex);
2069
2060
  break;
2070
2061
  // Close
2071
2062
  case 'Esc':
2063
+ case 27:
2072
2064
  this.close();
2073
2065
  break;
2074
2066
  }
package/dist/radar.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"radar.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/dist/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- declare const _default: "4.3.1-beta.2";
1
+ declare const _default: "4.3.2-beta.0";
2
2
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "radar-sdk-js",
3
- "version": "4.3.1-beta.2",
3
+ "version": "4.3.2-beta.0",
4
4
  "description": "Web Javascript SDK for Radar, location infrastructure for mobile and web apps.",
5
5
  "homepage": "https://radar.com",
6
6
  "type": "module",
package/src/core.ts ADDED
@@ -0,0 +1,215 @@
1
+ import Config from './config';
2
+ import Logger from './logger';
3
+ import Storage from './storage';
4
+ import Navigator from './navigator';
5
+ import { RadarPublishableKeyError } from './errors';
6
+
7
+ import AddressesAPI from './api/addresses';
8
+ import ConfigAPI from './api/config';
9
+ import ContextAPI from './api/context';
10
+ import ConversionsAPI from './api/conversions';
11
+ import GeocodingAPI from './api/geocoding';
12
+ import RoutingAPI from './api/routing';
13
+ import SearchAPI from './api/search';
14
+ import TrackAPI from './api/track';
15
+ import TripsAPI from './api/trips';
16
+ import VerifyAPI from './api/verify';
17
+
18
+ import SDK_VERSION from './version';
19
+
20
+ import type {
21
+ Location,
22
+ RadarAutocompleteParams,
23
+ RadarConversionParams,
24
+ RadarDistanceParams,
25
+ RadarForwardGeocodeParams,
26
+ RadarMatrixParams,
27
+ RadarMetadata,
28
+ RadarOptions,
29
+ RadarReverseGeocodeParams,
30
+ RadarSearchGeofencesParams,
31
+ RadarSearchPlacesParams,
32
+ RadarTrackParams,
33
+ RadarTripOptions,
34
+ RadarValidateAddressParams,
35
+ } from './types';
36
+
37
+ import '../styles/radar.css';
38
+
39
+
40
+ const isSecretKey = (key: string): boolean => (
41
+ key.includes('_sk_')
42
+ );
43
+ const isLiveKey = (key: string): boolean => (
44
+ key.includes('_live_')
45
+ );
46
+
47
+ class Radar {
48
+ public static get VERSION() {
49
+ return SDK_VERSION;
50
+ }
51
+
52
+ public static initialize(publishableKey: string, options: RadarOptions = {}) {
53
+ if (!publishableKey) {
54
+ throw new RadarPublishableKeyError('Publishable key required in initialization.');
55
+ }
56
+
57
+ if (isSecretKey(publishableKey)) {
58
+ throw new RadarPublishableKeyError('Secret keys are not allowed. Please use your Radar publishable key.');
59
+ }
60
+
61
+ // store settings in global config
62
+ const live = isLiveKey(publishableKey);
63
+ const logLevel = live ? 'error' : 'info';
64
+ const debug = !live;
65
+ const radarOptions = Object.assign(
66
+ Config.defaultOptions,
67
+ {
68
+ publishableKey,
69
+ live,
70
+ logLevel,
71
+ debug,
72
+ },
73
+ options,
74
+ );
75
+ Config.setup(radarOptions);
76
+
77
+ Logger.info(`initialized with ${live ? 'live' : 'test'} publishableKey.`);
78
+ if (options.debug) {
79
+ Logger.info(`using options: ${JSON.stringify(options)}`);
80
+ }
81
+
82
+ // NOTE(jasonl): this allows us to run jest tests
83
+ // without having to mock the ConfigAPI.getConfig call
84
+ if (!(window as any)?.RADAR_TEST_ENV) {
85
+ ConfigAPI.getConfig();
86
+ }
87
+ }
88
+
89
+ public static clear() {
90
+ Config.clear();
91
+ }
92
+
93
+ ///////////////////////
94
+ // geofencing platform
95
+ ///////////////////////
96
+
97
+ public static setUserId(userId?: string) {
98
+ if (!userId) {
99
+ Storage.removeItem(Storage.USER_ID);
100
+ return;
101
+ }
102
+ Storage.setItem(Storage.USER_ID, String(userId).trim());
103
+ }
104
+
105
+ public static setDescription(description?: string) {
106
+ if (!description) {
107
+ Storage.removeItem(Storage.DESCRIPTION);
108
+ return;
109
+ }
110
+ Storage.setItem(Storage.DESCRIPTION, String(description).trim());
111
+ }
112
+
113
+ public static setMetadata(metadata?: RadarMetadata) {
114
+ if (!metadata) {
115
+ Storage.removeItem(Storage.METADATA);
116
+ return;
117
+ }
118
+ Storage.setItem(Storage.METADATA, JSON.stringify(metadata));
119
+ }
120
+
121
+ public static getLocation() {
122
+ return Navigator.getCurrentPosition();
123
+ }
124
+
125
+ public static trackOnce(params: RadarTrackParams = {}) {
126
+ try {
127
+ return TrackAPI.trackOnce(params);
128
+ } finally {
129
+ ConfigAPI.getConfig(params); // call with updated permissions
130
+ }
131
+ }
132
+
133
+ public static trackVerified(params: RadarTrackParams = {}) {
134
+ return VerifyAPI.trackVerified(params);
135
+ }
136
+
137
+ public static getContext(params: Location) {
138
+ return ContextAPI.getContext(params);
139
+ }
140
+
141
+ public static setTripOptions(tripOptions?: RadarTripOptions) {
142
+ TripsAPI.setTripOptions(tripOptions);
143
+ }
144
+
145
+ public static clearTripOptions() {
146
+ TripsAPI.clearTripOptions();
147
+ }
148
+
149
+ public static getTripOptions() {
150
+ return TripsAPI.getTripOptions();
151
+ }
152
+
153
+ public static startTrip(tripOptions: RadarTripOptions) {
154
+ return TripsAPI.startTrip(tripOptions);
155
+ }
156
+
157
+ public static updateTrip(tripOptions: RadarTripOptions) {
158
+ return TripsAPI.updateTrip(tripOptions);
159
+ }
160
+
161
+ public static completeTrip() {
162
+ return TripsAPI.completeTrip();
163
+ }
164
+
165
+ public static cancelTrip() {
166
+ return TripsAPI.cancelTrip();
167
+ }
168
+
169
+ public static logConversion(params: RadarConversionParams) {
170
+ return ConversionsAPI.logConversion(params);
171
+ }
172
+
173
+
174
+ /////////////////
175
+ // maps platform
176
+ /////////////////
177
+
178
+ public static forwardGeocode(params: RadarForwardGeocodeParams) {
179
+ return GeocodingAPI.forwardGeocode(params);
180
+ }
181
+
182
+ public static reverseGeocode(params: RadarReverseGeocodeParams) {
183
+ return GeocodingAPI.reverseGeocode(params);
184
+ }
185
+
186
+ public static ipGeocode() {
187
+ return GeocodingAPI.ipGeocode();
188
+ }
189
+
190
+ public static autocomplete(params: RadarAutocompleteParams) {
191
+ return SearchAPI.autocomplete(params);
192
+ }
193
+
194
+ public static searchGeofences(params: RadarSearchGeofencesParams) {
195
+ return SearchAPI.searchGeofences(params);
196
+ }
197
+
198
+ public static searchPlaces(params: RadarSearchPlacesParams) {
199
+ return SearchAPI.searchPlaces(params);
200
+ }
201
+
202
+ public static validateAddress(params: RadarValidateAddressParams) {
203
+ return AddressesAPI.validateAddress(params);
204
+ }
205
+
206
+ public static distance(params: RadarDistanceParams) {
207
+ return RoutingAPI.distance(params);
208
+ }
209
+
210
+ public static matrix(params: RadarMatrixParams) {
211
+ return RoutingAPI.matrix(params);
212
+ }
213
+ }
214
+
215
+ export default Radar;
@@ -16,6 +16,10 @@ const CLASSNAMES = {
16
16
  NO_RESULTS: 'radar-no-results',
17
17
  };
18
18
 
19
+ const ARIA = {
20
+ EXPANDED: 'aria-expanded',
21
+ };
22
+
19
23
  const defaultAutocompleteOptions: RadarAutocompleteUIOptions = {
20
24
  container: 'autocomplete',
21
25
  debounceMS: 200, // Debounce time in milliseconds
@@ -132,10 +136,6 @@ class AutocompleteUI {
132
136
  // result list element
133
137
  this.resultsList = document.createElement('ul');
134
138
  this.resultsList.classList.add(CLASSNAMES.RESULTS_LIST);
135
- this.resultsList.classList.add('id', CLASSNAMES.RESULTS_LIST);
136
- this.resultsList.setAttribute('role', 'listbox');
137
- this.resultsList.setAttribute('aria-live', 'polite');
138
- this.resultsList.setAttribute('aria-label', 'Search results');
139
139
  setHeight(this.resultsList, this.config);
140
140
 
141
141
  if (containerEL.nodeName === 'INPUT') {
@@ -168,14 +168,6 @@ class AutocompleteUI {
168
168
  this.container.appendChild(this.wrapper);
169
169
  }
170
170
 
171
- // set aria roles
172
- this.inputField.setAttribute('role', 'combobox');
173
- this.inputField.setAttribute('aria-controls', CLASSNAMES.RESULTS_LIST);
174
- this.inputField.setAttribute('aria-expanded', 'false');
175
- this.inputField.setAttribute('aria-haspopup', 'listbox');
176
- this.inputField.setAttribute('aria-autocomplete', 'list');
177
- this.inputField.setAttribute('aria-activedescendant', '');
178
-
179
171
  // setup event listeners
180
172
  this.inputField.addEventListener('input', this.handleInput.bind(this));
181
173
  this.inputField.addEventListener('keydown', this.handleKeyboardNavigation.bind(this));
@@ -283,8 +275,6 @@ class AutocompleteUI {
283
275
  results.forEach((result, index) => {
284
276
  const li = document.createElement('li');
285
277
  li.classList.add(CLASSNAMES.RESULTS_ITEM);
286
- li.setAttribute('role', 'option');
287
- li.setAttribute('id', `item-${index}`);
288
278
 
289
279
  // construct result with bolded label
290
280
  let listContent;
@@ -346,7 +336,7 @@ class AutocompleteUI {
346
336
  return;
347
337
  }
348
338
 
349
- this.inputField.setAttribute('aria-expanded', 'true');
339
+ this.wrapper.setAttribute(ARIA.EXPANDED, 'true');
350
340
  this.resultsList.removeAttribute('hidden');
351
341
  this.isOpen = true;
352
342
  }
@@ -360,8 +350,7 @@ class AutocompleteUI {
360
350
  // (add 100ms delay if closed from link click)
361
351
  const linkClick = e && (e.relatedTarget === this.poweredByLink);
362
352
  setTimeout(() => {
363
- this.inputField.setAttribute('aria-expanded', 'false');
364
- this.inputField.setAttribute('aria-activedescendant', '');
353
+ this.wrapper.removeAttribute(ARIA.EXPANDED);
365
354
  this.resultsList.setAttribute('hidden', '');
366
355
  this.highlightedIndex = -1;
367
356
  this.isOpen = false;
@@ -391,41 +380,43 @@ class AutocompleteUI {
391
380
  // add class name to newly highlighted item
392
381
  resultItems[index].classList.add(CLASSNAMES.SELECTED_ITEM);
393
382
 
394
- // set aria active descendant
395
- this.inputField.setAttribute('aria-activedescendant', `item-${index}`);
396
-
397
383
  this.highlightedIndex = index;
398
384
  }
399
385
 
400
386
  public handleKeyboardNavigation(event: KeyboardEvent) {
401
- const key = event.key;
387
+ // fallback to deprecated "keyCode" if event.code not set
388
+ const code = event.code !== undefined ? event.code : event.keyCode;
402
389
 
403
390
  // allow event to propagate if result list is not open
404
391
  if (!this.isOpen) {
405
392
  return;
406
393
  }
407
394
 
408
- switch (key) {
395
+ switch (code) {
409
396
  // Next item
410
397
  case 'Tab':
411
398
  case 'ArrowDown':
399
+ case 40:
412
400
  event.preventDefault();
413
401
  this.goTo(this.highlightedIndex + 1);
414
402
  break;
415
403
 
416
404
  // Prev item
417
405
  case 'ArrowUp':
406
+ case 38:
418
407
  event.preventDefault();
419
408
  this.goTo(this.highlightedIndex - 1);
420
409
  break;
421
410
 
422
411
  // Select
423
412
  case 'Enter':
413
+ case 13:
424
414
  this.select(this.highlightedIndex);
425
415
  break;
426
416
 
427
417
  // Close
428
418
  case 'Esc':
419
+ case 27:
429
420
  this.close();
430
421
  break;
431
422
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '4.3.1-beta.2';
1
+ export default '4.3.2-beta.0';