@comicrelief/component-library 8.10.1 → 8.10.2

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.
@@ -56,6 +56,10 @@ const TextInputWithDropdown = /*#__PURE__*/_react.default.forwardRef((_ref, forw
56
56
  ['mousedown', 'touchstart'].forEach(event => document.removeEventListener(event, handleClickOutside));
57
57
  };
58
58
  }, [options.length, forceClosed, onChange]);
59
+ const closeDropdown = () => {
60
+ setForceClosed(true);
61
+ setActiveOption(-1);
62
+ };
59
63
 
60
64
  // Reset forceClosed when options change
61
65
  (0, _react.useEffect)(() => {
@@ -93,6 +97,7 @@ const TextInputWithDropdown = /*#__PURE__*/_react.default.forwardRef((_ref, forw
93
97
  onSelect,
94
98
  dropdownInstruction,
95
99
  activeOption,
100
+ closeDropdown,
96
101
  resetActiveOption: () => setActiveOption(-1)
97
102
  };
98
103
  return /*#__PURE__*/_react.default.createElement(_TextInputWithDropdown.Container, {
@@ -114,6 +119,7 @@ const Options = /*#__PURE__*/_react.default.forwardRef((_ref2, ref) => {
114
119
  dropdownInstruction,
115
120
  onSelect,
116
121
  activeOption,
122
+ closeDropdown,
117
123
  resetActiveOption,
118
124
  ...rest
119
125
  } = _ref2;
@@ -135,8 +141,11 @@ const Options = /*#__PURE__*/_react.default.forwardRef((_ref2, ref) => {
135
141
  role: "listbox",
136
142
  onBlur: onBlur,
137
143
  "aria-activedescendant": activeOption > -1 ? "option-".concat(activeOption) : undefined
138
- }, dropdownInstruction && /*#__PURE__*/_react.default.createElement(_TextInputWithDropdown.DropdownItem, {
139
- role: "option"
144
+ }, dropdownInstruction && /*#__PURE__*/_react.default.createElement(_TextInputWithDropdown.DropdownItemSelectable, {
145
+ id: "dropdown-instruction",
146
+ role: "option",
147
+ key: "dropdown-instruction",
148
+ onClick: closeDropdown
140
149
  }, /*#__PURE__*/_react.default.createElement(_TextInputWithDropdown.TextItalic, null, dropdownInstruction)), options.map((option, index) => /*#__PURE__*/_react.default.createElement(_TextInputWithDropdown.DropdownItemSelectable, {
141
150
  id: "option-".concat(index),
142
151
  role: "option",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@comicrelief/component-library",
3
3
  "author": "Comic Relief Engineering Team",
4
- "version": "8.10.1",
4
+ "version": "8.10.2",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -7,7 +7,6 @@ import {
7
7
  Container,
8
8
  Dropdown,
9
9
  DropdownList,
10
- DropdownItem,
11
10
  DropdownItemSelectable,
12
11
  TextItalic
13
12
  } from './TextInputWithDropdown.style';
@@ -66,6 +65,11 @@ const TextInputWithDropdown = React.forwardRef(
66
65
  };
67
66
  }, [options.length, forceClosed, onChange]);
68
67
 
68
+ const closeDropdown = () => {
69
+ setForceClosed(true);
70
+ setActiveOption(-1);
71
+ };
72
+
69
73
  // Reset forceClosed when options change
70
74
  useEffect(() => {
71
75
  setForceClosed(false);
@@ -112,6 +116,7 @@ const TextInputWithDropdown = React.forwardRef(
112
116
  onSelect,
113
117
  dropdownInstruction,
114
118
  activeOption,
119
+ closeDropdown,
115
120
  resetActiveOption: () => setActiveOption(-1)
116
121
  };
117
122
 
@@ -144,6 +149,7 @@ const Options = React.forwardRef(({
144
149
  dropdownInstruction,
145
150
  onSelect,
146
151
  activeOption,
152
+ closeDropdown,
147
153
  resetActiveOption,
148
154
  ...rest
149
155
  }, ref) => {
@@ -170,9 +176,16 @@ const Options = React.forwardRef(({
170
176
  }
171
177
  >
172
178
  {dropdownInstruction && (
173
- <DropdownItem role="option">
174
- <TextItalic>{dropdownInstruction}</TextItalic>
175
- </DropdownItem>
179
+ <DropdownItemSelectable
180
+ id="dropdown-instruction"
181
+ role="option"
182
+ key="dropdown-instruction"
183
+ onClick={closeDropdown}
184
+ >
185
+ <TextItalic>
186
+ {dropdownInstruction}
187
+ </TextItalic>
188
+ </DropdownItemSelectable>
176
189
  )}
177
190
  {options.map((option, index) => (
178
191
  <DropdownItemSelectable
@@ -220,7 +233,8 @@ Options.propTypes = {
220
233
  dropdownInstruction: PropTypes.string,
221
234
  activeOption: PropTypes.number.isRequired,
222
235
  resetActiveOption: PropTypes.func.isRequired,
223
- hideBorder: PropTypes.bool
236
+ hideBorder: PropTypes.bool,
237
+ closeDropdown: PropTypes.func
224
238
  };
225
239
 
226
240
  TextInputWithDropdown.displayName = 'TextInputWithDropdown';