react-instantsearch 7.38.0 → 7.39.1

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.
@@ -68,6 +68,7 @@ function Pagination(_0) {
68
68
  currentPage: page + 1,
69
69
  nbPages: nbPages
70
70
  }),
71
+ "aria-current": page === currentPage ? 'page' : undefined,
71
72
  href: createURL(page),
72
73
  onClick: function onClick() {
73
74
  return onNavigate(page);
@@ -160,13 +160,15 @@ function SearchBox(_0) {
160
160
  })), /*#__PURE__*/ _react.default.createElement("button", {
161
161
  className: (0, _instantsearchuicomponents.cx)('ais-SearchBox-submit', classNames.submit),
162
162
  type: "submit",
163
- title: translations.submitButtonTitle
163
+ title: translations.submitButtonTitle,
164
+ "aria-label": translations.submitButtonTitle
164
165
  }, /*#__PURE__*/ _react.default.createElement(SubmitIcon, {
165
166
  classNames: classNames
166
167
  })), /*#__PURE__*/ _react.default.createElement("button", {
167
168
  className: (0, _instantsearchuicomponents.cx)('ais-SearchBox-reset', classNames.reset),
168
169
  type: "reset",
169
170
  title: translations.resetButtonTitle,
171
+ "aria-label": translations.resetButtonTitle,
170
172
  hidden: value.length === 0 || isSearchStalled
171
173
  }, /*#__PURE__*/ _react.default.createElement(ResetIcon, {
172
174
  classNames: classNames
@@ -10,6 +10,8 @@ Object.defineProperty(exports, "ShowMoreButton", {
10
10
  }
11
11
  });
12
12
  var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
+ var _object_spread = require("@swc/helpers/_/_object_spread");
14
+ var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
13
15
  var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
14
16
  var _react = /*#__PURE__*/ _interop_require_default._(require("react"));
15
17
  function ShowMoreButton(_0) {
@@ -17,7 +19,10 @@ function ShowMoreButton(_0) {
17
19
  "isShowingMore",
18
20
  "translations"
19
21
  ]);
20
- return /*#__PURE__*/ _react.default.createElement("button", props, translations.showMoreButtonText({
22
+ return /*#__PURE__*/ _react.default.createElement("button", _object_spread_props._(_object_spread._({}, props), {
23
+ "aria-expanded": isShowingMore,
24
+ "aria-label": translations.showMoreButtonLabel
25
+ }), translations.showMoreButtonText({
21
26
  isShowingMore: isShowingMore
22
27
  }));
23
28
  }
@@ -9,12 +9,28 @@ Object.defineProperty(exports, "Stats", {
9
9
  return Stats;
10
10
  }
11
11
  });
12
- var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
12
+ var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
13
  var _object_spread = require("@swc/helpers/_/_object_spread");
14
14
  var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
15
15
  var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
16
+ var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
16
17
  var _instantsearchuicomponents = require("instantsearch-ui-components");
17
- var _react = /*#__PURE__*/ _interop_require_default._(require("react"));
18
+ var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
19
+ // Delay before announcing an update, so that rapid changes (e.g. typing in the
20
+ // search box) settle into a single announcement instead of piling up. Mirrors
21
+ // the debounce used by GOV.UK's accessible-autocomplete.
22
+ var ANNOUNCEMENT_DELAY = 1400;
23
+ var visuallyHiddenStyle = {
24
+ position: 'absolute',
25
+ width: 1,
26
+ height: 1,
27
+ padding: 0,
28
+ margin: -1,
29
+ overflow: 'hidden',
30
+ clip: 'rect(0, 0, 0, 0)',
31
+ whiteSpace: 'nowrap',
32
+ border: 0
33
+ };
18
34
  function Stats(_0) {
19
35
  var _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, nbHits = _0.nbHits, processingTimeMS = _0.processingTimeMS, nbSortedHits = _0.nbSortedHits, areHitsSorted = _0.areHitsSorted, translations = _0.translations, props = _object_without_properties._(_0, [
20
36
  "classNames",
@@ -30,9 +46,35 @@ function Stats(_0) {
30
46
  nbSortedHits: nbSortedHits,
31
47
  areHitsSorted: areHitsSorted
32
48
  };
49
+ var nextAnnouncement = translations.announcementText ? translations.announcementText(translationOptions) : '';
50
+ var _useState = _sliced_to_array._((0, _react.useState)(''), 2), announcement = _useState[0], setAnnouncement = _useState[1];
51
+ var timerRef = (0, _react.useRef)(undefined);
52
+ var isInitialRef = (0, _react.useRef)(true);
53
+ (0, _react.useEffect)(function() {
54
+ // Don't announce the initial results, only subsequent changes.
55
+ if (isInitialRef.current) {
56
+ isInitialRef.current = false;
57
+ return undefined;
58
+ }
59
+ clearTimeout(timerRef.current);
60
+ timerRef.current = setTimeout(function() {
61
+ setAnnouncement(nextAnnouncement);
62
+ }, ANNOUNCEMENT_DELAY);
63
+ return function() {
64
+ return clearTimeout(timerRef.current);
65
+ };
66
+ }, [
67
+ nextAnnouncement
68
+ ]);
33
69
  return /*#__PURE__*/ _react.default.createElement("div", _object_spread_props._(_object_spread._({}, props), {
34
70
  className: (0, _instantsearchuicomponents.cx)('ais-Stats', classNames.root, props.className)
35
71
  }), /*#__PURE__*/ _react.default.createElement("span", {
36
72
  className: "ais-Stats-text"
37
- }, translations.rootElementText(translationOptions)));
73
+ }, translations.rootElementText(translationOptions)), /*#__PURE__*/ _react.default.createElement("span", {
74
+ className: "ais-Stats-announcement",
75
+ role: "status",
76
+ "aria-live": "polite",
77
+ "aria-atomic": "true",
78
+ style: visuallyHiddenStyle
79
+ }, announcement));
38
80
  }
@@ -105,7 +105,8 @@ function RefinementList(_0) {
105
105
  onToggleShowMore: toggleShowMore,
106
106
  isShowingMore: isShowingMore,
107
107
  translations: {
108
- showMoreButtonText: mergedTranslations.showMoreButtonText
108
+ showMoreButtonText: mergedTranslations.showMoreButtonText,
109
+ showMoreButtonLabel: translations === null || translations === void 0 ? void 0 : translations.showMoreButtonLabel
109
110
  }
110
111
  };
111
112
  return /*#__PURE__*/ _react.default.createElement(_RefinementList.RefinementList, _object_spread_props._(_object_spread._({}, props, uiProps), {
@@ -30,6 +30,9 @@ function Stats(_0) {
30
30
  translations: _object_spread._({
31
31
  rootElementText: function rootElementText(options) {
32
32
  return "".concat(options.areHitsSorted ? getSortedResultsSentence(options) : getResultsSentence(options), " found in ").concat(options.processingTimeMS.toLocaleString(), "ms");
33
+ },
34
+ announcementText: function announcementText(options) {
35
+ return options.areHitsSorted ? getSortedResultsSentence(options) : getResultsSentence(options);
33
36
  }
34
37
  }, translations)
35
38
  };
@@ -57,6 +57,7 @@ function Pagination(_0) {
57
57
  currentPage: page + 1,
58
58
  nbPages: nbPages
59
59
  }),
60
+ "aria-current": page === currentPage ? 'page' : undefined,
60
61
  href: createURL(page),
61
62
  onClick: function onClick() {
62
63
  return onNavigate(page);
@@ -149,13 +149,15 @@ function SearchBox(_0) {
149
149
  })), /*#__PURE__*/ React.createElement("button", {
150
150
  className: cx('ais-SearchBox-submit', classNames.submit),
151
151
  type: "submit",
152
- title: translations.submitButtonTitle
152
+ title: translations.submitButtonTitle,
153
+ "aria-label": translations.submitButtonTitle
153
154
  }, /*#__PURE__*/ React.createElement(SubmitIcon, {
154
155
  classNames: classNames
155
156
  })), /*#__PURE__*/ React.createElement("button", {
156
157
  className: cx('ais-SearchBox-reset', classNames.reset),
157
158
  type: "reset",
158
159
  title: translations.resetButtonTitle,
160
+ "aria-label": translations.resetButtonTitle,
159
161
  hidden: value.length === 0 || isSearchStalled
160
162
  }, /*#__PURE__*/ React.createElement(ResetIcon, {
161
163
  classNames: classNames
@@ -14,6 +14,10 @@ export type ShowMoreButtonTranslations = {
14
14
  * Alternative text for the "Show more" button.
15
15
  */
16
16
  showMoreButtonText: (options: ShowMoreButtonTextOptions) => string;
17
+ /**
18
+ * Accessible name (aria-label) for the show more button.
19
+ */
20
+ showMoreButtonLabel?: string;
17
21
  };
18
22
  export declare function ShowMoreButton({ isShowingMore, translations, ...props }: ShowMoreButtonProps): React.JSX.Element;
19
23
  export {};
@@ -1,3 +1,5 @@
1
+ import { _ as _$2 } from '@swc/helpers/esm/_object_spread.js';
2
+ import { _ as _$1 } from '@swc/helpers/esm/_object_spread_props.js';
1
3
  import { _ } from '@swc/helpers/esm/_object_without_properties.js';
2
4
  import React from 'react';
3
5
 
@@ -6,7 +8,10 @@ function ShowMoreButton(_0) {
6
8
  "isShowingMore",
7
9
  "translations"
8
10
  ]);
9
- return /*#__PURE__*/ React.createElement("button", props, translations.showMoreButtonText({
11
+ return /*#__PURE__*/ React.createElement("button", _$1(_$2({}, props), {
12
+ "aria-expanded": isShowingMore,
13
+ "aria-label": translations.showMoreButtonLabel
14
+ }), translations.showMoreButtonText({
10
15
  isShowingMore: isShowingMore
11
16
  }));
12
17
  }
@@ -7,6 +7,12 @@ export type StatsProps = React.ComponentProps<'div'> & {
7
7
  classNames?: Partial<StatsClassNames>;
8
8
  translations: {
9
9
  rootElementText: StatsTranslations;
10
+ /**
11
+ * Text announced to assistive technologies when the results change. It
12
+ * omits volatile details (such as the processing time) so that only the
13
+ * meaningful result count is spoken.
14
+ */
15
+ announcementText?: StatsTranslations;
10
16
  };
11
17
  };
12
18
  export type StatsTranslationOptions = Pick<StatsProps, 'nbHits' | 'processingTimeMS' | 'nbSortedHits' | 'areHitsSorted'>;
@@ -1,9 +1,25 @@
1
- import { _ as _$2 } from '@swc/helpers/esm/_object_spread.js';
2
- import { _ as _$1 } from '@swc/helpers/esm/_object_spread_props.js';
1
+ import { _ as _$3 } from '@swc/helpers/esm/_object_spread.js';
2
+ import { _ as _$2 } from '@swc/helpers/esm/_object_spread_props.js';
3
3
  import { _ } from '@swc/helpers/esm/_object_without_properties.js';
4
+ import { _ as _$1 } from '@swc/helpers/esm/_sliced_to_array.js';
4
5
  import { cx } from 'instantsearch-ui-components';
5
- import React from 'react';
6
+ import React, { useState, useRef, useEffect } from 'react';
6
7
 
8
+ // Delay before announcing an update, so that rapid changes (e.g. typing in the
9
+ // search box) settle into a single announcement instead of piling up. Mirrors
10
+ // the debounce used by GOV.UK's accessible-autocomplete.
11
+ var ANNOUNCEMENT_DELAY = 1400;
12
+ var visuallyHiddenStyle = {
13
+ position: 'absolute',
14
+ width: 1,
15
+ height: 1,
16
+ padding: 0,
17
+ margin: -1,
18
+ overflow: 'hidden',
19
+ clip: 'rect(0, 0, 0, 0)',
20
+ whiteSpace: 'nowrap',
21
+ border: 0
22
+ };
7
23
  function Stats(_0) {
8
24
  var _0_classNames = _0.classNames, classNames = _0_classNames === void 0 ? {} : _0_classNames, nbHits = _0.nbHits, processingTimeMS = _0.processingTimeMS, nbSortedHits = _0.nbSortedHits, areHitsSorted = _0.areHitsSorted, translations = _0.translations, props = _(_0, [
9
25
  "classNames",
@@ -19,11 +35,37 @@ function Stats(_0) {
19
35
  nbSortedHits: nbSortedHits,
20
36
  areHitsSorted: areHitsSorted
21
37
  };
22
- return /*#__PURE__*/ React.createElement("div", _$1(_$2({}, props), {
38
+ var nextAnnouncement = translations.announcementText ? translations.announcementText(translationOptions) : '';
39
+ var _useState = _$1(useState(''), 2), announcement = _useState[0], setAnnouncement = _useState[1];
40
+ var timerRef = useRef(undefined);
41
+ var isInitialRef = useRef(true);
42
+ useEffect(function() {
43
+ // Don't announce the initial results, only subsequent changes.
44
+ if (isInitialRef.current) {
45
+ isInitialRef.current = false;
46
+ return undefined;
47
+ }
48
+ clearTimeout(timerRef.current);
49
+ timerRef.current = setTimeout(function() {
50
+ setAnnouncement(nextAnnouncement);
51
+ }, ANNOUNCEMENT_DELAY);
52
+ return function() {
53
+ return clearTimeout(timerRef.current);
54
+ };
55
+ }, [
56
+ nextAnnouncement
57
+ ]);
58
+ return /*#__PURE__*/ React.createElement("div", _$2(_$3({}, props), {
23
59
  className: cx('ais-Stats', classNames.root, props.className)
24
60
  }), /*#__PURE__*/ React.createElement("span", {
25
61
  className: "ais-Stats-text"
26
- }, translations.rootElementText(translationOptions)));
62
+ }, translations.rootElementText(translationOptions)), /*#__PURE__*/ React.createElement("span", {
63
+ className: "ais-Stats-announcement",
64
+ role: "status",
65
+ "aria-live": "polite",
66
+ "aria-atomic": "true",
67
+ style: visuallyHiddenStyle
68
+ }, announcement));
27
69
  }
28
70
 
29
71
  export { Stats };
@@ -94,7 +94,8 @@ function RefinementList(_0) {
94
94
  onToggleShowMore: toggleShowMore,
95
95
  isShowingMore: isShowingMore,
96
96
  translations: {
97
- showMoreButtonText: mergedTranslations.showMoreButtonText
97
+ showMoreButtonText: mergedTranslations.showMoreButtonText,
98
+ showMoreButtonLabel: translations === null || translations === void 0 ? void 0 : translations.showMoreButtonLabel
98
99
  }
99
100
  };
100
101
  return /*#__PURE__*/ React.createElement(RefinementList$1, _$3(_$2({}, props, uiProps), {
@@ -19,6 +19,9 @@ function Stats(_0) {
19
19
  translations: _$1({
20
20
  rootElementText: function rootElementText(options) {
21
21
  return "".concat(options.areHitsSorted ? getSortedResultsSentence(options) : getResultsSentence(options), " found in ").concat(options.processingTimeMS.toLocaleString(), "ms");
22
+ },
23
+ announcementText: function announcementText(options) {
24
+ return options.areHitsSorted ? getSortedResultsSentence(options) : getResultsSentence(options);
22
25
  }
23
26
  }, translations)
24
27
  };