downshift 9.1.0-alpha.5 → 9.1.0-alpha.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "downshift",
3
- "version": "9.1.0-alpha.5",
3
+ "version": "9.1.0-alpha.6",
4
4
  "description": "🏎 A set of primitives to build simple, flexible, WAI-ARIA compliant React autocomplete, combobox or select dropdown components.",
5
5
  "main": "dist/downshift.cjs.js",
6
6
  "react-native": "dist/downshift.native.cjs.js",
@@ -4123,27 +4123,20 @@ var _useTagGroup = function useTagGroup(userProps) {
4123
4123
  tagGroupId: props.tagGroupId
4124
4124
  });
4125
4125
  var itemRefs = React.useRef({});
4126
+ var previousActiveIndexRef = React.useRef(activeIndex);
4126
4127
  var previousItemsLengthRef = React.useRef(items.length);
4127
- var isInitialMount = useIsInitialMount();
4128
4128
 
4129
4129
  /* Effects */
4130
4130
 
4131
4131
  useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
4132
4132
  React.useEffect(function () {
4133
- if (isInitialMount) {
4134
- return;
4135
- }
4136
- if (previousItemsLengthRef.current < items.length) {
4137
- return;
4138
- }
4139
- if (activeIndex >= 0 && activeIndex < Object.keys(itemRefs.current).length) {
4133
+ if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
4140
4134
  var _itemRefs$current$ele;
4141
4135
  (_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
4142
4136
  }
4143
- }, [activeIndex, elementIds, isInitialMount, items.length]);
4144
- React.useEffect(function () {
4137
+ previousActiveIndexRef.current = activeIndex;
4145
4138
  previousItemsLengthRef.current = items.length;
4146
- });
4139
+ }, [activeIndex, elementIds, items]);
4147
4140
 
4148
4141
  /* Getter functions */
4149
4142
 
@@ -4101,27 +4101,20 @@ var _useTagGroup = function useTagGroup(userProps) {
4101
4101
  tagGroupId: props.tagGroupId
4102
4102
  });
4103
4103
  var itemRefs = useRef({});
4104
+ var previousActiveIndexRef = useRef(activeIndex);
4104
4105
  var previousItemsLengthRef = useRef(items.length);
4105
- var isInitialMount = useIsInitialMount();
4106
4106
 
4107
4107
  /* Effects */
4108
4108
 
4109
4109
  useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
4110
4110
  useEffect(function () {
4111
- if (isInitialMount) {
4112
- return;
4113
- }
4114
- if (previousItemsLengthRef.current < items.length) {
4115
- return;
4116
- }
4117
- if (activeIndex >= 0 && activeIndex < Object.keys(itemRefs.current).length) {
4111
+ if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
4118
4112
  var _itemRefs$current$ele;
4119
4113
  (_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
4120
4114
  }
4121
- }, [activeIndex, elementIds, isInitialMount, items.length]);
4122
- useEffect(function () {
4115
+ previousActiveIndexRef.current = activeIndex;
4123
4116
  previousItemsLengthRef.current = items.length;
4124
- });
4117
+ }, [activeIndex, elementIds, items]);
4125
4118
 
4126
4119
  /* Getter functions */
4127
4120
 
@@ -4376,27 +4376,20 @@
4376
4376
  tagGroupId: props.tagGroupId
4377
4377
  });
4378
4378
  var itemRefs = React.useRef({});
4379
+ var previousActiveIndexRef = React.useRef(activeIndex);
4379
4380
  var previousItemsLengthRef = React.useRef(items.length);
4380
- var isInitialMount = useIsInitialMount();
4381
4381
 
4382
4382
  /* Effects */
4383
4383
 
4384
4384
  useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
4385
4385
  React.useEffect(function () {
4386
- if (isInitialMount) {
4387
- return;
4388
- }
4389
- if (previousItemsLengthRef.current < items.length) {
4390
- return;
4391
- }
4392
- if (activeIndex >= 0 && activeIndex < Object.keys(itemRefs.current).length) {
4386
+ if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
4393
4387
  var _itemRefs$current$ele;
4394
4388
  (_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
4395
4389
  }
4396
- }, [activeIndex, elementIds, isInitialMount, items.length]);
4397
- React.useEffect(function () {
4390
+ previousActiveIndexRef.current = activeIndex;
4398
4391
  previousItemsLengthRef.current = items.length;
4399
- });
4392
+ }, [activeIndex, elementIds, items]);
4400
4393
 
4401
4394
  /* Getter functions */
4402
4395