@docsearch/react 3.5.2 → 3.6.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/dist/esm/DocSearchButton.js +46 -5
- package/dist/esm/DocSearchModal.js +1 -1
- package/dist/esm/SearchBox.d.ts +1 -0
- package/dist/esm/SearchBox.js +6 -2
- package/dist/esm/__tests__/api.test.js +20 -21
- package/dist/esm/icons/SearchIcon.js +2 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/index.js +2 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -60,9 +60,50 @@ export var DocSearchButton = React.forwardRef(function (_ref, ref) {
|
|
|
60
60
|
className: "DocSearch-Button-Placeholder"
|
|
61
61
|
}, buttonText)), /*#__PURE__*/React.createElement("span", {
|
|
62
62
|
className: "DocSearch-Button-Keys"
|
|
63
|
-
}, key !== null && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(
|
|
64
|
-
|
|
65
|
-
}, key === ACTION_KEY_DEFAULT ? /*#__PURE__*/React.createElement(ControlKeyIcon, null) : key), /*#__PURE__*/React.createElement(
|
|
66
|
-
|
|
63
|
+
}, key !== null && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DocSearchButtonKey, {
|
|
64
|
+
reactsToKey: key === ACTION_KEY_DEFAULT ? ACTION_KEY_DEFAULT : 'Meta'
|
|
65
|
+
}, key === ACTION_KEY_DEFAULT ? /*#__PURE__*/React.createElement(ControlKeyIcon, null) : key), /*#__PURE__*/React.createElement(DocSearchButtonKey, {
|
|
66
|
+
reactsToKey: "k"
|
|
67
67
|
}, "K"))));
|
|
68
|
-
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
function DocSearchButtonKey(_ref2) {
|
|
71
|
+
var reactsToKey = _ref2.reactsToKey,
|
|
72
|
+
children = _ref2.children;
|
|
73
|
+
|
|
74
|
+
var _useState3 = useState(false),
|
|
75
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
76
|
+
isKeyDown = _useState4[0],
|
|
77
|
+
setIsKeyDown = _useState4[1];
|
|
78
|
+
|
|
79
|
+
useEffect(function () {
|
|
80
|
+
if (!reactsToKey) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function handleKeyDown(e) {
|
|
85
|
+
if (e.key === reactsToKey) {
|
|
86
|
+
setIsKeyDown(true);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function handleKeyUp(e) {
|
|
91
|
+
if (e.key === reactsToKey || // keyup doesn't fire when Command is held down,
|
|
92
|
+
// workaround is to mark key as also released when Command is released
|
|
93
|
+
// See https://stackoverflow.com/a/73419500
|
|
94
|
+
e.key === 'Meta') {
|
|
95
|
+
setIsKeyDown(false);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
window.addEventListener('keydown', handleKeyDown);
|
|
100
|
+
window.addEventListener('keyup', handleKeyUp);
|
|
101
|
+
return function () {
|
|
102
|
+
window.removeEventListener('keydown', handleKeyDown);
|
|
103
|
+
window.removeEventListener('keyup', handleKeyUp);
|
|
104
|
+
};
|
|
105
|
+
}, [reactsToKey]);
|
|
106
|
+
return /*#__PURE__*/React.createElement("kbd", {
|
|
107
|
+
className: isKeyDown ? 'DocSearch-Button-Key DocSearch-Button-Key--pressed' : 'DocSearch-Button-Key'
|
|
108
|
+
}, children);
|
|
109
|
+
}
|
|
@@ -315,7 +315,7 @@ export function DocSearchModal(_ref) {
|
|
|
315
315
|
document.body.classList.remove('DocSearch--active'); // IE11 doesn't support `scrollTo` so we check that the method exists
|
|
316
316
|
// first.
|
|
317
317
|
|
|
318
|
-
(_window$scrollTo = (_window = window).scrollTo) === null || _window$scrollTo === void 0
|
|
318
|
+
(_window$scrollTo = (_window = window).scrollTo) === null || _window$scrollTo === void 0 || _window$scrollTo.call(_window, 0, initialScrollY);
|
|
319
319
|
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
320
320
|
}, []);
|
|
321
321
|
React.useEffect(function () {
|
package/dist/esm/SearchBox.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export declare type SearchBoxTranslations = Partial<{
|
|
|
7
7
|
resetButtonAriaLabel: string;
|
|
8
8
|
cancelButtonText: string;
|
|
9
9
|
cancelButtonAriaLabel: string;
|
|
10
|
+
searchInputLabel: string;
|
|
10
11
|
}>;
|
|
11
12
|
interface SearchBoxProps extends AutocompleteApi<InternalDocSearchHit, React.FormEvent, React.MouseEvent, React.KeyboardEvent> {
|
|
12
13
|
state: AutocompleteState<InternalDocSearchHit>;
|
package/dist/esm/SearchBox.js
CHANGED
|
@@ -23,7 +23,9 @@ export function SearchBox(_ref) {
|
|
|
23
23
|
_translations$cancelB = translations.cancelButtonText,
|
|
24
24
|
cancelButtonText = _translations$cancelB === void 0 ? 'Cancel' : _translations$cancelB,
|
|
25
25
|
_translations$cancelB2 = translations.cancelButtonAriaLabel,
|
|
26
|
-
cancelButtonAriaLabel = _translations$cancelB2 === void 0 ? 'Cancel' : _translations$cancelB2
|
|
26
|
+
cancelButtonAriaLabel = _translations$cancelB2 === void 0 ? 'Cancel' : _translations$cancelB2,
|
|
27
|
+
_translations$searchI = translations.searchInputLabel,
|
|
28
|
+
searchInputLabel = _translations$searchI === void 0 ? 'Search' : _translations$searchI;
|
|
27
29
|
|
|
28
30
|
var _props$getFormProps = props.getFormProps({
|
|
29
31
|
inputElement: props.inputRef.current
|
|
@@ -48,7 +50,9 @@ export function SearchBox(_ref) {
|
|
|
48
50
|
onReset: onReset
|
|
49
51
|
}, /*#__PURE__*/React.createElement("label", _extends({
|
|
50
52
|
className: "DocSearch-MagnifierLabel"
|
|
51
|
-
}, props.getLabelProps()), /*#__PURE__*/React.createElement(SearchIcon, null)
|
|
53
|
+
}, props.getLabelProps()), /*#__PURE__*/React.createElement(SearchIcon, null), /*#__PURE__*/React.createElement("span", {
|
|
54
|
+
className: "DocSearch-VisuallyHiddenForAccessibility"
|
|
55
|
+
}, searchInputLabel)), /*#__PURE__*/React.createElement("div", {
|
|
52
56
|
className: "DocSearch-LoadingIndicator"
|
|
53
57
|
}, /*#__PURE__*/React.createElement(LoadingIcon, null)), /*#__PURE__*/React.createElement("input", _extends({
|
|
54
58
|
className: "DocSearch-Input",
|
|
@@ -43,22 +43,15 @@ function noResultSearch(_queries, _requestOptions) {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
describe('api', function () {
|
|
46
|
-
var container;
|
|
47
46
|
var docSearchSelector = '.DocSearch';
|
|
48
|
-
beforeEach(function () {
|
|
49
|
-
container = document.createElement('div');
|
|
50
|
-
document.body.appendChild(container);
|
|
51
|
-
});
|
|
52
|
-
afterEach(function () {
|
|
53
|
-
document.body.removeChild(container);
|
|
54
|
-
container = null;
|
|
55
|
-
});
|
|
56
47
|
it('renders with minimal parameters', function () {
|
|
57
48
|
render( /*#__PURE__*/React.createElement(DocSearch, null));
|
|
58
49
|
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
|
|
59
50
|
});
|
|
60
51
|
describe('translations', function () {
|
|
61
52
|
it('overrides the default DocSearchButton text', function () {
|
|
53
|
+
var _document$querySelect, _document$querySelect2;
|
|
54
|
+
|
|
62
55
|
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
63
56
|
translations: {
|
|
64
57
|
button: {
|
|
@@ -68,8 +61,8 @@ describe('api', function () {
|
|
|
68
61
|
}
|
|
69
62
|
}));
|
|
70
63
|
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
|
|
71
|
-
expect(document.querySelector('.DocSearch-Button-Placeholder').innerHTML).toBe('Recherche');
|
|
72
|
-
expect(document.querySelector('.DocSearch-Button').getAttribute('aria-label')).toBe('Recherche');
|
|
64
|
+
expect((_document$querySelect = document.querySelector('.DocSearch-Button-Placeholder')) === null || _document$querySelect === void 0 ? void 0 : _document$querySelect.innerHTML).toBe('Recherche');
|
|
65
|
+
expect((_document$querySelect2 = document.querySelector('.DocSearch-Button')) === null || _document$querySelect2 === void 0 ? void 0 : _document$querySelect2.getAttribute('aria-label')).toBe('Recherche');
|
|
73
66
|
});
|
|
74
67
|
it('overrides the default DocSearchModal startScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
75
68
|
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
@@ -202,6 +195,9 @@ describe('api', function () {
|
|
|
202
195
|
}, _callee5);
|
|
203
196
|
})));
|
|
204
197
|
it('overrides the default DocSearchModal searchbox text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
|
|
198
|
+
var _document$querySelect3, _document$querySelect4, _document$querySelect5, _document$querySelect6;
|
|
199
|
+
|
|
200
|
+
var searchInputLabel;
|
|
205
201
|
return regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
206
202
|
while (1) switch (_context7.prev = _context7.next) {
|
|
207
203
|
case 0:
|
|
@@ -212,13 +208,13 @@ describe('api', function () {
|
|
|
212
208
|
resetButtonTitle: 'Effacer',
|
|
213
209
|
resetButtonAriaLabel: 'Effacer',
|
|
214
210
|
cancelButtonText: 'Annuler',
|
|
215
|
-
cancelButtonAriaLabel: 'Annuler'
|
|
211
|
+
cancelButtonAriaLabel: 'Annuler',
|
|
212
|
+
searchInputLabel: 'Recherche'
|
|
216
213
|
}
|
|
217
214
|
}
|
|
218
215
|
}
|
|
219
216
|
}));
|
|
220
|
-
|
|
221
|
-
_context7.next = 4;
|
|
217
|
+
_context7.next = 3;
|
|
222
218
|
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
|
|
223
219
|
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
224
220
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -239,13 +235,16 @@ describe('api', function () {
|
|
|
239
235
|
}, _callee6);
|
|
240
236
|
})));
|
|
241
237
|
|
|
242
|
-
case
|
|
243
|
-
|
|
244
|
-
expect(document.querySelector(
|
|
245
|
-
expect(document.querySelector('.DocSearch-
|
|
246
|
-
expect(document.querySelector('.DocSearch-
|
|
238
|
+
case 3:
|
|
239
|
+
searchInputLabel = document.querySelector('.DocSearch-MagnifierLabel');
|
|
240
|
+
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
|
|
241
|
+
expect((_document$querySelect3 = document.querySelector('.DocSearch-Cancel')) === null || _document$querySelect3 === void 0 ? void 0 : _document$querySelect3.innerHTML).toBe('Annuler');
|
|
242
|
+
expect((_document$querySelect4 = document.querySelector('.DocSearch-Cancel')) === null || _document$querySelect4 === void 0 ? void 0 : _document$querySelect4.getAttribute('aria-label')).toBe('Annuler');
|
|
243
|
+
expect((_document$querySelect5 = document.querySelector('.DocSearch-Reset')) === null || _document$querySelect5 === void 0 ? void 0 : _document$querySelect5.getAttribute('title')).toBe('Effacer');
|
|
244
|
+
expect((_document$querySelect6 = document.querySelector('.DocSearch-Reset')) === null || _document$querySelect6 === void 0 ? void 0 : _document$querySelect6.getAttribute('aria-label')).toBe('Effacer');
|
|
245
|
+
expect(searchInputLabel === null || searchInputLabel === void 0 ? void 0 : searchInputLabel.textContent).toBe('Recherche');
|
|
247
246
|
|
|
248
|
-
case
|
|
247
|
+
case 10:
|
|
249
248
|
case "end":
|
|
250
249
|
return _context7.stop();
|
|
251
250
|
}
|
|
@@ -449,7 +448,7 @@ describe('api', function () {
|
|
|
449
448
|
expect(screen.getByText(/No results for/)).toBeInTheDocument();
|
|
450
449
|
link = document.querySelector('.DocSearch-Help a');
|
|
451
450
|
expect(link).toBeInTheDocument();
|
|
452
|
-
expect(link.getAttribute('href')).toBe('https://github.com/algolia/docsearch/issues/new?title=q');
|
|
451
|
+
expect(link === null || link === void 0 ? void 0 : link.getAttribute('href')).toBe('https://github.com/algolia/docsearch/issues/new?title=q');
|
|
453
452
|
|
|
454
453
|
case 9:
|
|
455
454
|
case "end":
|
|
@@ -4,7 +4,8 @@ export function SearchIcon() {
|
|
|
4
4
|
width: "20",
|
|
5
5
|
height: "20",
|
|
6
6
|
className: "DocSearch-Search-Icon",
|
|
7
|
-
viewBox: "0 0 20 20"
|
|
7
|
+
viewBox: "0 0 20 20",
|
|
8
|
+
"aria-hidden": "true"
|
|
8
9
|
}, /*#__PURE__*/React.createElement("path", {
|
|
9
10
|
d: "M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z",
|
|
10
11
|
stroke: "currentColor",
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "3.
|
|
1
|
+
export declare const version = "3.6.0";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '3.
|
|
1
|
+
export var version = '3.6.0';
|