bright-components 10.2.3 → 10.2.6

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.
@@ -0,0 +1,22 @@
1
+ {
2
+ "eslint.format.enable": true,
3
+ "editor.renderWhitespace": "all",
4
+ "editor.defaultFormatter": "dbaeumer.vscode-eslint",
5
+ "editor.formatOnSave": true,
6
+ "editor.formatOnPaste": true,
7
+ "cSpell.words": [
8
+ "autobind",
9
+ "brighthr",
10
+ "cronersupplieddocuments",
11
+ "firstname",
12
+ "Formik",
13
+ "lastname",
14
+ "pathnames",
15
+ "pendo",
16
+ "previewable",
17
+ "selectall",
18
+ "tailwindcss",
19
+ "testid",
20
+ "testprops"
21
+ ]
22
+ }
@@ -108,10 +108,18 @@ const ResponsiveTabs = _ref => {
108
108
  } = _ref,
109
109
  rest = _objectWithoutProperties(_ref, ["tabs", "defaultIndex", "children", "autoTabWidth", "onSelected"]);
110
110
 
111
- const [index, setIndex] = (0, _react.useState)(defaultIndex || 0);
111
+ const tabs = tabsProp || _react.default.Children.map(children, child => {
112
+ return child && child.props && child.props.name ? {
113
+ name: child.props.name,
114
+ counter: child.props.counter
115
+ } : null;
116
+ });
117
+
118
+ const [index, setIndex] = (0, _react.useState)(defaultIndex < tabs.length ? defaultIndex : 0);
119
+
120
+ const onSelectChange = (event, _tabs) => {
121
+ const names = _tabs.map(tab => tab.name);
112
122
 
113
- const onSelectChange = (event, tabs) => {
114
- const names = tabs.map(tab => tab.name);
115
123
  const newIndex = names.indexOf(event.target.value);
116
124
  setIndex(newIndex);
117
125
  };
@@ -120,13 +128,6 @@ const ResponsiveTabs = _ref => {
120
128
  setIndex(newIndex);
121
129
  };
122
130
 
123
- const tabs = tabsProp || _react.default.Children.map(children, child => {
124
- return child && child.props && child.props.name ? {
125
- name: child.props.name,
126
- counter: child.props.counter
127
- } : null;
128
- });
129
-
130
131
  const DesktopTabList = autoTabWidth ? AutoWidthTabList : StyledTabList;
131
132
  return _react.default.createElement(_Tabs.default, _extends({
132
133
  selectedIndex: index
@@ -151,7 +152,7 @@ const ResponsiveTabs = _ref => {
151
152
  onSelected(i);
152
153
  }
153
154
  },
154
- value: tabs[index].name
155
+ value: tabs == null ? void 0 : tabs[index].name
155
156
  }, tabs.map(_ref3 => {
156
157
  let {
157
158
  name,
@@ -171,7 +171,7 @@ class Typeahead extends _react.default.Component {
171
171
  let nextIndex = highlightIndex;
172
172
  const isActionKey = ['ArrowDown', 'ArrowUp', 'Enter', 'Escape', 'Tab'].includes(e.key);
173
173
 
174
- if (!isActionKey) {
174
+ if (!isActionKey || !this.options[highlightIndex]) {
175
175
  return;
176
176
  }
177
177
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bright-components",
3
- "version": "10.2.3",
3
+ "version": "10.2.6",
4
4
  "private": false,
5
5
  "main": "./dist",
6
6
  "repository": {
@@ -94,18 +94,6 @@ const ResponsiveTabs = ({
94
94
  onSelected,
95
95
  ...rest
96
96
  }) => {
97
- const [index, setIndex] = useState(defaultIndex || 0);
98
-
99
- const onSelectChange = (event, tabs) => {
100
- const names = tabs.map(tab => tab.name);
101
- const newIndex = names.indexOf(event.target.value);
102
- setIndex(newIndex);
103
- };
104
-
105
- const onSelect = newIndex => {
106
- setIndex(newIndex);
107
- };
108
-
109
97
  const tabs =
110
98
  tabsProp ||
111
99
  React.Children.map(children, child => {
@@ -117,6 +105,20 @@ const ResponsiveTabs = ({
117
105
  : null;
118
106
  });
119
107
 
108
+ const [index, setIndex] = useState(
109
+ defaultIndex < tabs.length ? defaultIndex : 0
110
+ );
111
+
112
+ const onSelectChange = (event, _tabs) => {
113
+ const names = _tabs.map(tab => tab.name);
114
+ const newIndex = names.indexOf(event.target.value);
115
+ setIndex(newIndex);
116
+ };
117
+
118
+ const onSelect = newIndex => {
119
+ setIndex(newIndex);
120
+ };
121
+
120
122
  const DesktopTabList = autoTabWidth ? AutoWidthTabList : StyledTabList;
121
123
 
122
124
  return (
@@ -140,7 +142,7 @@ const ResponsiveTabs = ({
140
142
  onSelected(i);
141
143
  }
142
144
  }}
143
- value={tabs[index].name}
145
+ value={tabs?.[index].name}
144
146
  >
145
147
  {tabs.map(({ name, counter = null }) => (
146
148
  <Option key={name} value={name}>
@@ -7,6 +7,20 @@ import ResponsiveTabs from '.';
7
7
  jest.mock('react-ga');
8
8
 
9
9
  describe('<ResponsiveTabs />', () => {
10
+ it('should handle when defaultIndex is larger than the amount of tabs', () => {
11
+ const { getByRole, getAllByRole } = render(
12
+ <ResponsiveTabs defaultIndex={3}>
13
+ <TabPanel name="One">One</TabPanel>
14
+ <TabPanel name="Two">Two</TabPanel>
15
+ </ResponsiveTabs>
16
+ );
17
+
18
+ expect(getByRole('combobox')).toBeInTheDocument();
19
+ expect(getAllByRole('option')).toHaveLength(2);
20
+
21
+ // doesn't throw an error is good
22
+ });
23
+
10
24
  it('should render a dropdown for selecting tabs on mobile', () => {
11
25
  const { getByRole, getAllByRole } = render(
12
26
  <ResponsiveTabs>
@@ -144,7 +144,7 @@ class Typeahead extends React.Component {
144
144
  'Tab'
145
145
  ].includes(e.key);
146
146
 
147
- if (!isActionKey) {
147
+ if (!isActionKey || !this.options[highlightIndex]) {
148
148
  return;
149
149
  }
150
150
 
@@ -228,6 +228,13 @@ describe('<Typeahead />', () => {
228
228
  [firstOption, secondOption] = wrapper.getAllByRole('listitem');
229
229
  expect(firstOption).not.toHaveStyleRule('background', '#D0EBFD');
230
230
  expect(secondOption).toHaveStyleRule('background', '#D0EBFD');
231
+
232
+ fireEvent.keyDown(input, { key: 'ArrowUp' });
233
+ fireEvent.keyDown(input, { key: 'ArrowUp' });
234
+ fireEvent.keyDown(input, { key: 'ArrowUp' });
235
+
236
+ expect(firstOption).toHaveStyleRule('background', '#D0EBFD');
237
+ expect(secondOption).not.toHaveStyleRule('background', '#D0EBFD');
231
238
  });
232
239
 
233
240
  it('should highlight a new option on the up arrow key', () => {
@@ -284,5 +291,16 @@ describe('<Typeahead />', () => {
284
291
 
285
292
  expect(scrollIntoView).not.toHaveBeenCalled();
286
293
  });
294
+
295
+ it('should handle live updates to the list changing the length of the list', () => {
296
+ const input = wrapper.getByPlaceholderText('Search or select');
297
+
298
+ fireEvent.focus(input);
299
+
300
+ wrapper.rerender(<Typeahead {...props} options={[]} />);
301
+ fireEvent.keyDown(input, { key: 'Enter' });
302
+
303
+ expect(setSelected).toHaveBeenCalledTimes(0);
304
+ });
287
305
  });
288
306
  });