@comicrelief/component-library 8.10.1 → 8.11.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.
@@ -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",
@@ -35,7 +35,6 @@ const KEY_CODE_ENTER = 13;
35
35
  * - only throw errors with user-friendly messages
36
36
  *
37
37
  * Any errors thrown will be caught and the message will be displayed to the user.
38
- *
39
38
  * The `onSelect` function will receive the chosen option.
40
39
  *
41
40
  * @param name
@@ -118,7 +117,8 @@ const Lookup = _ref2 => {
118
117
  onClick: () => handler(),
119
118
  loading: isSearching,
120
119
  disabled: isSearching,
121
- loadingText: "Searching"
120
+ loadingText: "Searching",
121
+ "data-test": "lookupButton"
122
122
  }, buttonText));
123
123
  };
124
124
  var _default = exports.default = Lookup;
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.11.0",
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';
@@ -11,7 +11,6 @@ const StyledButton = styled(ButtonWithStates)`${({ theme }) => css`
11
11
  background-color: ${theme.color('white')};
12
12
  padding-left: ${spacing('lg')};
13
13
  padding-right: ${spacing('lg')};
14
-
15
14
  &:hover {
16
15
  color: ${theme.color('grey_dark')};
17
16
  background-color: ${theme.color('white')};
@@ -33,7 +32,6 @@ const KEY_CODE_ENTER = 13;
33
32
  * - only throw errors with user-friendly messages
34
33
  *
35
34
  * Any errors thrown will be caught and the message will be displayed to the user.
36
- *
37
35
  * The `onSelect` function will receive the chosen option.
38
36
  *
39
37
  * @param name
@@ -121,6 +119,7 @@ const Lookup = ({
121
119
  loading={isSearching}
122
120
  disabled={isSearching}
123
121
  loadingText="Searching"
122
+ data-test="lookupButton"
124
123
  >
125
124
  {buttonText}
126
125
  </StyledButton>