downshift 9.1.0-alpha.7 → 9.3.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.
- package/README.md +6 -7
- package/dist/{downshift.cjs.js → downshift.cjs.cjs} +24 -16
- package/dist/{downshift.esm.js → downshift.esm.mjs} +24 -16
- package/dist/{downshift.native.cjs.js → downshift.native.cjs.cjs} +24 -16
- package/dist/{downshift.nativeweb.cjs.js → downshift.nativeweb.cjs.cjs} +24 -16
- package/dist/downshift.umd.js +59 -36
- package/dist/downshift.umd.js.map +1 -1
- package/dist/downshift.umd.min.js +1 -1
- package/dist/downshift.umd.min.js.map +1 -1
- package/dist/hooks/useSelect/utils/getItemIndexByCharacterKey.d.ts +8 -1
- package/dist/hooks/useTagGroup/__tests__/utils/renderTagGroup.d.ts +1 -1
- package/dist/hooks/useTagGroup/utils/index.d.ts +1 -0
- package/dist/hooks/useTagGroup/utils/useRovingTagFocus.d.ts +6 -0
- package/dist/index.d.ts +6 -1
- package/package.json +46 -44
- package/preact/dist/{downshift.cjs.js → downshift.cjs.cjs} +24 -16
- package/preact/dist/{downshift.esm.js → downshift.esm.mjs} +24 -16
- package/preact/dist/downshift.umd.js +35 -19
- package/preact/dist/downshift.umd.js.map +1 -1
- package/preact/dist/downshift.umd.min.js +1 -10
- package/preact/dist/downshift.umd.min.js.map +1 -1
- package/preact/package.json +3 -3
- package/dist/hooks/useSelect/types.d.ts +0 -7
package/README.md
CHANGED
|
@@ -46,9 +46,8 @@ list below.
|
|
|
46
46
|
|
|
47
47
|
- [useSelect][useselect-readme] for a custom select component.
|
|
48
48
|
- [useCombobox][combobox-readme] for a combobox or autocomplete input.
|
|
49
|
-
- [
|
|
50
|
-
|
|
51
|
-
navigating between the selected items.
|
|
49
|
+
- [useTagGroup][tag-group-readme] for a tag group component. Also useful to
|
|
50
|
+
build a multiple selection combobox or select component with tags.
|
|
52
51
|
|
|
53
52
|
The second solution is the `Downshift` component, which can also be used to
|
|
54
53
|
create accessible combobox and select components, providing the logic in the
|
|
@@ -734,8 +733,8 @@ check could fail even if the ref is correctly forwarded to the root DOM
|
|
|
734
733
|
component. In these cases, you can provide the object
|
|
735
734
|
`{suppressRefError : true}` as the second argument to `getRootProps` to
|
|
736
735
|
completely bypass the check.\
|
|
737
|
-
**Please use it with extreme care and only if you are absolutely sure that the
|
|
738
|
-
is correctly forwarded otherwise `Downshift` will unexpectedly fail.**\
|
|
736
|
+
**Please use it with extreme care and only if you are absolutely sure that the
|
|
737
|
+
ref is correctly forwarded otherwise `Downshift` will unexpectedly fail.**\
|
|
739
738
|
See [#235](https://github.com/downshift-js/downshift/issues/235) for the
|
|
740
739
|
discussion that lead to this.
|
|
741
740
|
|
|
@@ -1516,8 +1515,8 @@ MIT
|
|
|
1516
1515
|
https://github.com/downshift-js/downshift/blob/master/src/hooks/useSelect
|
|
1517
1516
|
[combobox-readme]:
|
|
1518
1517
|
https://github.com/downshift-js/downshift/tree/master/src/hooks/useCombobox
|
|
1519
|
-
[
|
|
1520
|
-
https://github.com/downshift-js/downshift/tree/master/src/hooks/
|
|
1518
|
+
[tag-group-readme]:
|
|
1519
|
+
https://github.com/downshift-js/downshift/tree/master/src/hooks/useTagGroup
|
|
1521
1520
|
[bundle-phobia-link]: https://bundlephobia.com/result?p=downshift@3.4.8
|
|
1522
1521
|
[aria]: https://www.w3.org/TR/wai-aria-practices/
|
|
1523
1522
|
[combobox-aria-example]:
|
|
@@ -2312,11 +2312,11 @@ function getItemIndexByCharacterKey(_ref) {
|
|
|
2312
2312
|
itemToString = _ref.itemToString,
|
|
2313
2313
|
isItemDisabled = _ref.isItemDisabled;
|
|
2314
2314
|
var lowerCasedKeysSoFar = keysSoFar.toLowerCase();
|
|
2315
|
-
for (var
|
|
2315
|
+
for (var _index = 0; _index < items.length; _index++) {
|
|
2316
2316
|
// if we already have a search query in progress, we also consider the current highlighted item.
|
|
2317
|
-
var offsetIndex = (
|
|
2318
|
-
var
|
|
2319
|
-
if (
|
|
2317
|
+
var offsetIndex = (_index + highlightedIndex + (keysSoFar.length < 2 ? 1 : 0)) % items.length;
|
|
2318
|
+
var _item = items[offsetIndex];
|
|
2319
|
+
if (_item !== undefined && itemToString(_item).toLowerCase().startsWith(lowerCasedKeysSoFar) && !isItemDisabled(_item, offsetIndex)) {
|
|
2320
2320
|
return offsetIndex;
|
|
2321
2321
|
}
|
|
2322
2322
|
}
|
|
@@ -4128,6 +4128,24 @@ function getMergedProps(userProps) {
|
|
|
4128
4128
|
}, userProps);
|
|
4129
4129
|
}
|
|
4130
4130
|
|
|
4131
|
+
/**
|
|
4132
|
+
* Focuses the tag at activeIndex when it changes or when an item is removed.
|
|
4133
|
+
*/
|
|
4134
|
+
function useRovingTagFocus(activeIndex, itemsLength, getTagId) {
|
|
4135
|
+
var itemRefs = React__namespace.useRef({});
|
|
4136
|
+
var previousActiveIndexRef = React__namespace.useRef(activeIndex);
|
|
4137
|
+
var previousItemsLengthRef = React__namespace.useRef(itemsLength);
|
|
4138
|
+
React__namespace.useEffect(function () {
|
|
4139
|
+
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === itemsLength + 1) {
|
|
4140
|
+
var _itemRefs$current$get;
|
|
4141
|
+
(_itemRefs$current$get = itemRefs.current[getTagId(activeIndex)]) == null || _itemRefs$current$get.focus();
|
|
4142
|
+
}
|
|
4143
|
+
previousActiveIndexRef.current = activeIndex;
|
|
4144
|
+
previousItemsLengthRef.current = itemsLength;
|
|
4145
|
+
}, [activeIndex, getTagId, itemsLength]);
|
|
4146
|
+
return itemRefs;
|
|
4147
|
+
}
|
|
4148
|
+
|
|
4131
4149
|
var propTypes = {
|
|
4132
4150
|
isItemDisabled: PropTypes.func
|
|
4133
4151
|
};
|
|
@@ -4161,21 +4179,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4161
4179
|
id: props.id,
|
|
4162
4180
|
tagGroupId: props.tagGroupId
|
|
4163
4181
|
});
|
|
4164
|
-
var itemRefs = React.useRef({});
|
|
4165
|
-
var previousActiveIndexRef = React.useRef(activeIndex);
|
|
4166
|
-
var previousItemsLengthRef = React.useRef(items.length);
|
|
4167
4182
|
|
|
4168
4183
|
/* Effects */
|
|
4169
4184
|
|
|
4170
4185
|
useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
|
|
4171
|
-
|
|
4172
|
-
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
|
|
4173
|
-
var _itemRefs$current$ele;
|
|
4174
|
-
(_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
|
|
4175
|
-
}
|
|
4176
|
-
previousActiveIndexRef.current = activeIndex;
|
|
4177
|
-
previousItemsLengthRef.current = items.length;
|
|
4178
|
-
}, [activeIndex, elementIds, items]);
|
|
4186
|
+
var itemRefs = useRovingTagFocus(activeIndex, items.length, elementIds.getTagId);
|
|
4179
4187
|
|
|
4180
4188
|
/* Getter functions */
|
|
4181
4189
|
|
|
@@ -4243,7 +4251,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4243
4251
|
itemRefs.current[tagId] = itemNode;
|
|
4244
4252
|
}
|
|
4245
4253
|
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4246
|
-
}, [dispatch, elementIds, latest]);
|
|
4254
|
+
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4247
4255
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4248
4256
|
var index = options.index,
|
|
4249
4257
|
onClick = options.onClick,
|
|
@@ -2290,11 +2290,11 @@ function getItemIndexByCharacterKey(_ref) {
|
|
|
2290
2290
|
itemToString = _ref.itemToString,
|
|
2291
2291
|
isItemDisabled = _ref.isItemDisabled;
|
|
2292
2292
|
var lowerCasedKeysSoFar = keysSoFar.toLowerCase();
|
|
2293
|
-
for (var
|
|
2293
|
+
for (var _index = 0; _index < items.length; _index++) {
|
|
2294
2294
|
// if we already have a search query in progress, we also consider the current highlighted item.
|
|
2295
|
-
var offsetIndex = (
|
|
2296
|
-
var
|
|
2297
|
-
if (
|
|
2295
|
+
var offsetIndex = (_index + highlightedIndex + (keysSoFar.length < 2 ? 1 : 0)) % items.length;
|
|
2296
|
+
var _item = items[offsetIndex];
|
|
2297
|
+
if (_item !== undefined && itemToString(_item).toLowerCase().startsWith(lowerCasedKeysSoFar) && !isItemDisabled(_item, offsetIndex)) {
|
|
2298
2298
|
return offsetIndex;
|
|
2299
2299
|
}
|
|
2300
2300
|
}
|
|
@@ -4106,6 +4106,24 @@ function getMergedProps(userProps) {
|
|
|
4106
4106
|
}, userProps);
|
|
4107
4107
|
}
|
|
4108
4108
|
|
|
4109
|
+
/**
|
|
4110
|
+
* Focuses the tag at activeIndex when it changes or when an item is removed.
|
|
4111
|
+
*/
|
|
4112
|
+
function useRovingTagFocus(activeIndex, itemsLength, getTagId) {
|
|
4113
|
+
var itemRefs = React.useRef({});
|
|
4114
|
+
var previousActiveIndexRef = React.useRef(activeIndex);
|
|
4115
|
+
var previousItemsLengthRef = React.useRef(itemsLength);
|
|
4116
|
+
React.useEffect(function () {
|
|
4117
|
+
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === itemsLength + 1) {
|
|
4118
|
+
var _itemRefs$current$get;
|
|
4119
|
+
(_itemRefs$current$get = itemRefs.current[getTagId(activeIndex)]) == null || _itemRefs$current$get.focus();
|
|
4120
|
+
}
|
|
4121
|
+
previousActiveIndexRef.current = activeIndex;
|
|
4122
|
+
previousItemsLengthRef.current = itemsLength;
|
|
4123
|
+
}, [activeIndex, getTagId, itemsLength]);
|
|
4124
|
+
return itemRefs;
|
|
4125
|
+
}
|
|
4126
|
+
|
|
4109
4127
|
var propTypes = {
|
|
4110
4128
|
isItemDisabled: PropTypes.func
|
|
4111
4129
|
};
|
|
@@ -4139,21 +4157,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4139
4157
|
id: props.id,
|
|
4140
4158
|
tagGroupId: props.tagGroupId
|
|
4141
4159
|
});
|
|
4142
|
-
var itemRefs = useRef({});
|
|
4143
|
-
var previousActiveIndexRef = useRef(activeIndex);
|
|
4144
|
-
var previousItemsLengthRef = useRef(items.length);
|
|
4145
4160
|
|
|
4146
4161
|
/* Effects */
|
|
4147
4162
|
|
|
4148
4163
|
useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
|
|
4149
|
-
|
|
4150
|
-
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
|
|
4151
|
-
var _itemRefs$current$ele;
|
|
4152
|
-
(_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
|
|
4153
|
-
}
|
|
4154
|
-
previousActiveIndexRef.current = activeIndex;
|
|
4155
|
-
previousItemsLengthRef.current = items.length;
|
|
4156
|
-
}, [activeIndex, elementIds, items]);
|
|
4164
|
+
var itemRefs = useRovingTagFocus(activeIndex, items.length, elementIds.getTagId);
|
|
4157
4165
|
|
|
4158
4166
|
/* Getter functions */
|
|
4159
4167
|
|
|
@@ -4221,7 +4229,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4221
4229
|
itemRefs.current[tagId] = itemNode;
|
|
4222
4230
|
}
|
|
4223
4231
|
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4224
|
-
}, [dispatch, elementIds, latest]);
|
|
4232
|
+
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4225
4233
|
var getTagRemoveProps = useCallback(function (options) {
|
|
4226
4234
|
var index = options.index,
|
|
4227
4235
|
onClick = options.onClick,
|
|
@@ -2162,11 +2162,11 @@ function getItemIndexByCharacterKey(_ref) {
|
|
|
2162
2162
|
itemToString = _ref.itemToString,
|
|
2163
2163
|
isItemDisabled = _ref.isItemDisabled;
|
|
2164
2164
|
var lowerCasedKeysSoFar = keysSoFar.toLowerCase();
|
|
2165
|
-
for (var
|
|
2165
|
+
for (var _index = 0; _index < items.length; _index++) {
|
|
2166
2166
|
// if we already have a search query in progress, we also consider the current highlighted item.
|
|
2167
|
-
var offsetIndex = (
|
|
2168
|
-
var
|
|
2169
|
-
if (
|
|
2167
|
+
var offsetIndex = (_index + highlightedIndex + (keysSoFar.length < 2 ? 1 : 0)) % items.length;
|
|
2168
|
+
var _item = items[offsetIndex];
|
|
2169
|
+
if (_item !== undefined && itemToString(_item).toLowerCase().startsWith(lowerCasedKeysSoFar) && !isItemDisabled(_item, offsetIndex)) {
|
|
2170
2170
|
return offsetIndex;
|
|
2171
2171
|
}
|
|
2172
2172
|
}
|
|
@@ -3978,6 +3978,24 @@ function getMergedProps(userProps) {
|
|
|
3978
3978
|
}, userProps);
|
|
3979
3979
|
}
|
|
3980
3980
|
|
|
3981
|
+
/**
|
|
3982
|
+
* Focuses the tag at activeIndex when it changes or when an item is removed.
|
|
3983
|
+
*/
|
|
3984
|
+
function useRovingTagFocus(activeIndex, itemsLength, getTagId) {
|
|
3985
|
+
var itemRefs = React__namespace.useRef({});
|
|
3986
|
+
var previousActiveIndexRef = React__namespace.useRef(activeIndex);
|
|
3987
|
+
var previousItemsLengthRef = React__namespace.useRef(itemsLength);
|
|
3988
|
+
React__namespace.useEffect(function () {
|
|
3989
|
+
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === itemsLength + 1) {
|
|
3990
|
+
var _itemRefs$current$get;
|
|
3991
|
+
(_itemRefs$current$get = itemRefs.current[getTagId(activeIndex)]) == null || _itemRefs$current$get.focus();
|
|
3992
|
+
}
|
|
3993
|
+
previousActiveIndexRef.current = activeIndex;
|
|
3994
|
+
previousItemsLengthRef.current = itemsLength;
|
|
3995
|
+
}, [activeIndex, getTagId, itemsLength]);
|
|
3996
|
+
return itemRefs;
|
|
3997
|
+
}
|
|
3998
|
+
|
|
3981
3999
|
var propTypes = {
|
|
3982
4000
|
isItemDisabled: PropTypes.func
|
|
3983
4001
|
};
|
|
@@ -4011,21 +4029,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4011
4029
|
id: props.id,
|
|
4012
4030
|
tagGroupId: props.tagGroupId
|
|
4013
4031
|
});
|
|
4014
|
-
var itemRefs = React.useRef({});
|
|
4015
|
-
var previousActiveIndexRef = React.useRef(activeIndex);
|
|
4016
|
-
var previousItemsLengthRef = React.useRef(items.length);
|
|
4017
4032
|
|
|
4018
4033
|
/* Effects */
|
|
4019
4034
|
|
|
4020
4035
|
useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
|
|
4021
|
-
|
|
4022
|
-
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
|
|
4023
|
-
var _itemRefs$current$ele;
|
|
4024
|
-
(_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
|
|
4025
|
-
}
|
|
4026
|
-
previousActiveIndexRef.current = activeIndex;
|
|
4027
|
-
previousItemsLengthRef.current = items.length;
|
|
4028
|
-
}, [activeIndex, elementIds, items]);
|
|
4036
|
+
var itemRefs = useRovingTagFocus(activeIndex, items.length, elementIds.getTagId);
|
|
4029
4037
|
|
|
4030
4038
|
/* Getter functions */
|
|
4031
4039
|
|
|
@@ -4093,7 +4101,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4093
4101
|
itemRefs.current[tagId] = itemNode;
|
|
4094
4102
|
}
|
|
4095
4103
|
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4096
|
-
}, [dispatch, elementIds, latest]);
|
|
4104
|
+
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4097
4105
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4098
4106
|
var index = options.index,
|
|
4099
4107
|
onClick = options.onClick,
|
|
@@ -2307,11 +2307,11 @@ function getItemIndexByCharacterKey(_ref) {
|
|
|
2307
2307
|
itemToString = _ref.itemToString,
|
|
2308
2308
|
isItemDisabled = _ref.isItemDisabled;
|
|
2309
2309
|
var lowerCasedKeysSoFar = keysSoFar.toLowerCase();
|
|
2310
|
-
for (var
|
|
2310
|
+
for (var _index = 0; _index < items.length; _index++) {
|
|
2311
2311
|
// if we already have a search query in progress, we also consider the current highlighted item.
|
|
2312
|
-
var offsetIndex = (
|
|
2313
|
-
var
|
|
2314
|
-
if (
|
|
2312
|
+
var offsetIndex = (_index + highlightedIndex + (keysSoFar.length < 2 ? 1 : 0)) % items.length;
|
|
2313
|
+
var _item = items[offsetIndex];
|
|
2314
|
+
if (_item !== undefined && itemToString(_item).toLowerCase().startsWith(lowerCasedKeysSoFar) && !isItemDisabled(_item, offsetIndex)) {
|
|
2315
2315
|
return offsetIndex;
|
|
2316
2316
|
}
|
|
2317
2317
|
}
|
|
@@ -4111,6 +4111,24 @@ function getMergedProps(userProps) {
|
|
|
4111
4111
|
}, userProps);
|
|
4112
4112
|
}
|
|
4113
4113
|
|
|
4114
|
+
/**
|
|
4115
|
+
* Focuses the tag at activeIndex when it changes or when an item is removed.
|
|
4116
|
+
*/
|
|
4117
|
+
function useRovingTagFocus(activeIndex, itemsLength, getTagId) {
|
|
4118
|
+
var itemRefs = React__namespace.useRef({});
|
|
4119
|
+
var previousActiveIndexRef = React__namespace.useRef(activeIndex);
|
|
4120
|
+
var previousItemsLengthRef = React__namespace.useRef(itemsLength);
|
|
4121
|
+
React__namespace.useEffect(function () {
|
|
4122
|
+
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === itemsLength + 1) {
|
|
4123
|
+
var _itemRefs$current$get;
|
|
4124
|
+
(_itemRefs$current$get = itemRefs.current[getTagId(activeIndex)]) == null || _itemRefs$current$get.focus();
|
|
4125
|
+
}
|
|
4126
|
+
previousActiveIndexRef.current = activeIndex;
|
|
4127
|
+
previousItemsLengthRef.current = itemsLength;
|
|
4128
|
+
}, [activeIndex, getTagId, itemsLength]);
|
|
4129
|
+
return itemRefs;
|
|
4130
|
+
}
|
|
4131
|
+
|
|
4114
4132
|
var propTypes = {
|
|
4115
4133
|
isItemDisabled: PropTypes.func
|
|
4116
4134
|
};
|
|
@@ -4144,21 +4162,11 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4144
4162
|
id: props.id,
|
|
4145
4163
|
tagGroupId: props.tagGroupId
|
|
4146
4164
|
});
|
|
4147
|
-
var itemRefs = React.useRef({});
|
|
4148
|
-
var previousActiveIndexRef = React.useRef(activeIndex);
|
|
4149
|
-
var previousItemsLengthRef = React.useRef(items.length);
|
|
4150
4165
|
|
|
4151
4166
|
/* Effects */
|
|
4152
4167
|
|
|
4153
4168
|
useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
|
|
4154
|
-
|
|
4155
|
-
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
|
|
4156
|
-
var _itemRefs$current$ele;
|
|
4157
|
-
(_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
|
|
4158
|
-
}
|
|
4159
|
-
previousActiveIndexRef.current = activeIndex;
|
|
4160
|
-
previousItemsLengthRef.current = items.length;
|
|
4161
|
-
}, [activeIndex, elementIds, items]);
|
|
4169
|
+
var itemRefs = useRovingTagFocus(activeIndex, items.length, elementIds.getTagId);
|
|
4162
4170
|
|
|
4163
4171
|
/* Getter functions */
|
|
4164
4172
|
|
|
@@ -4226,7 +4234,7 @@ var _useTagGroup = function useTagGroup(userProps) {
|
|
|
4226
4234
|
itemRefs.current[tagId] = itemNode;
|
|
4227
4235
|
}
|
|
4228
4236
|
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
4229
|
-
}, [dispatch, elementIds, latest]);
|
|
4237
|
+
}, [dispatch, elementIds, latest, itemRefs]);
|
|
4230
4238
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
4231
4239
|
var index = options.index,
|
|
4232
4240
|
onClick = options.onClick,
|
package/dist/downshift.umd.js
CHANGED
|
@@ -250,11 +250,11 @@
|
|
|
250
250
|
return reactIs_development$1;
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
var hasRequiredReactIs;
|
|
253
|
+
var hasRequiredReactIs$1;
|
|
254
254
|
|
|
255
|
-
function requireReactIs () {
|
|
256
|
-
if (hasRequiredReactIs) return reactIs$1.exports;
|
|
257
|
-
hasRequiredReactIs = 1;
|
|
255
|
+
function requireReactIs$1 () {
|
|
256
|
+
if (hasRequiredReactIs$1) return reactIs$1.exports;
|
|
257
|
+
hasRequiredReactIs$1 = 1;
|
|
258
258
|
|
|
259
259
|
{
|
|
260
260
|
reactIs$1.exports = requireReactIs_development$1();
|
|
@@ -407,9 +407,9 @@
|
|
|
407
407
|
var printWarning = function() {};
|
|
408
408
|
|
|
409
409
|
{
|
|
410
|
-
var ReactPropTypesSecret = requireReactPropTypesSecret();
|
|
410
|
+
var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
|
|
411
411
|
var loggedTypeFailures = {};
|
|
412
|
-
var has = requireHas();
|
|
412
|
+
var has = /*@__PURE__*/ requireHas();
|
|
413
413
|
|
|
414
414
|
printWarning = function(text) {
|
|
415
415
|
var message = 'Warning: ' + text;
|
|
@@ -515,12 +515,12 @@
|
|
|
515
515
|
if (hasRequiredFactoryWithTypeCheckers) return factoryWithTypeCheckers;
|
|
516
516
|
hasRequiredFactoryWithTypeCheckers = 1;
|
|
517
517
|
|
|
518
|
-
var ReactIs = requireReactIs();
|
|
518
|
+
var ReactIs = requireReactIs$1();
|
|
519
519
|
var assign = requireObjectAssign();
|
|
520
520
|
|
|
521
|
-
var ReactPropTypesSecret = requireReactPropTypesSecret();
|
|
522
|
-
var has = requireHas();
|
|
523
|
-
var checkPropTypes = requireCheckPropTypes();
|
|
521
|
+
var ReactPropTypesSecret = /*@__PURE__*/ requireReactPropTypesSecret();
|
|
522
|
+
var has = /*@__PURE__*/ requireHas();
|
|
523
|
+
var checkPropTypes = /*@__PURE__*/ requireCheckPropTypes();
|
|
524
524
|
|
|
525
525
|
var printWarning = function() {};
|
|
526
526
|
|
|
@@ -1126,16 +1126,23 @@
|
|
|
1126
1126
|
* LICENSE file in the root directory of this source tree.
|
|
1127
1127
|
*/
|
|
1128
1128
|
|
|
1129
|
-
|
|
1130
|
-
var ReactIs = requireReactIs();
|
|
1129
|
+
var hasRequiredPropTypes;
|
|
1131
1130
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1131
|
+
function requirePropTypes () {
|
|
1132
|
+
if (hasRequiredPropTypes) return propTypes$6.exports;
|
|
1133
|
+
hasRequiredPropTypes = 1;
|
|
1134
|
+
{
|
|
1135
|
+
var ReactIs = requireReactIs$1();
|
|
1136
|
+
|
|
1137
|
+
// By explicitly using `prop-types` you are opting into new development behavior.
|
|
1138
|
+
// http://fb.me/prop-types-in-prod
|
|
1139
|
+
var throwOnDirectAccess = true;
|
|
1140
|
+
propTypes$6.exports = /*@__PURE__*/ requireFactoryWithTypeCheckers()(ReactIs.isElement, throwOnDirectAccess);
|
|
1141
|
+
}
|
|
1142
|
+
return propTypes$6.exports;
|
|
1136
1143
|
}
|
|
1137
1144
|
|
|
1138
|
-
var propTypesExports =
|
|
1145
|
+
var propTypesExports = /*@__PURE__*/ requirePropTypes();
|
|
1139
1146
|
var PropTypes = /*@__PURE__*/getDefaultExportFromCjs(propTypesExports);
|
|
1140
1147
|
|
|
1141
1148
|
var reactIs = {exports: {}};
|
|
@@ -1369,11 +1376,19 @@
|
|
|
1369
1376
|
return reactIs_development;
|
|
1370
1377
|
}
|
|
1371
1378
|
|
|
1372
|
-
|
|
1373
|
-
|
|
1379
|
+
var hasRequiredReactIs;
|
|
1380
|
+
|
|
1381
|
+
function requireReactIs () {
|
|
1382
|
+
if (hasRequiredReactIs) return reactIs.exports;
|
|
1383
|
+
hasRequiredReactIs = 1;
|
|
1384
|
+
|
|
1385
|
+
{
|
|
1386
|
+
reactIs.exports = requireReactIs_development();
|
|
1387
|
+
}
|
|
1388
|
+
return reactIs.exports;
|
|
1374
1389
|
}
|
|
1375
1390
|
|
|
1376
|
-
var reactIsExports =
|
|
1391
|
+
var reactIsExports = requireReactIs();
|
|
1377
1392
|
|
|
1378
1393
|
var unknown = '__autocomplete_unknown__' ;
|
|
1379
1394
|
var mouseUp = '__autocomplete_mouseup__' ;
|
|
@@ -3650,11 +3665,11 @@
|
|
|
3650
3665
|
itemToString = _ref.itemToString,
|
|
3651
3666
|
isItemDisabled = _ref.isItemDisabled;
|
|
3652
3667
|
var lowerCasedKeysSoFar = keysSoFar.toLowerCase();
|
|
3653
|
-
for (var
|
|
3668
|
+
for (var _index = 0; _index < items.length; _index++) {
|
|
3654
3669
|
// if we already have a search query in progress, we also consider the current highlighted item.
|
|
3655
|
-
var offsetIndex = (
|
|
3656
|
-
var
|
|
3657
|
-
if (
|
|
3670
|
+
var offsetIndex = (_index + highlightedIndex + (keysSoFar.length < 2 ? 1 : 0)) % items.length;
|
|
3671
|
+
var _item = items[offsetIndex];
|
|
3672
|
+
if (_item !== undefined && itemToString(_item).toLowerCase().startsWith(lowerCasedKeysSoFar) && !isItemDisabled(_item, offsetIndex)) {
|
|
3658
3673
|
return offsetIndex;
|
|
3659
3674
|
}
|
|
3660
3675
|
}
|
|
@@ -5466,6 +5481,24 @@
|
|
|
5466
5481
|
}, userProps);
|
|
5467
5482
|
}
|
|
5468
5483
|
|
|
5484
|
+
/**
|
|
5485
|
+
* Focuses the tag at activeIndex when it changes or when an item is removed.
|
|
5486
|
+
*/
|
|
5487
|
+
function useRovingTagFocus(activeIndex, itemsLength, getTagId) {
|
|
5488
|
+
var itemRefs = React__namespace.useRef({});
|
|
5489
|
+
var previousActiveIndexRef = React__namespace.useRef(activeIndex);
|
|
5490
|
+
var previousItemsLengthRef = React__namespace.useRef(itemsLength);
|
|
5491
|
+
React__namespace.useEffect(function () {
|
|
5492
|
+
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === itemsLength + 1) {
|
|
5493
|
+
var _itemRefs$current$get;
|
|
5494
|
+
(_itemRefs$current$get = itemRefs.current[getTagId(activeIndex)]) == null || _itemRefs$current$get.focus();
|
|
5495
|
+
}
|
|
5496
|
+
previousActiveIndexRef.current = activeIndex;
|
|
5497
|
+
previousItemsLengthRef.current = itemsLength;
|
|
5498
|
+
}, [activeIndex, getTagId, itemsLength]);
|
|
5499
|
+
return itemRefs;
|
|
5500
|
+
}
|
|
5501
|
+
|
|
5469
5502
|
var propTypes = {
|
|
5470
5503
|
isItemDisabled: PropTypes.func
|
|
5471
5504
|
};
|
|
@@ -5499,21 +5532,11 @@
|
|
|
5499
5532
|
id: props.id,
|
|
5500
5533
|
tagGroupId: props.tagGroupId
|
|
5501
5534
|
});
|
|
5502
|
-
var itemRefs = React.useRef({});
|
|
5503
|
-
var previousActiveIndexRef = React.useRef(activeIndex);
|
|
5504
|
-
var previousItemsLengthRef = React.useRef(items.length);
|
|
5505
5535
|
|
|
5506
5536
|
/* Effects */
|
|
5507
5537
|
|
|
5508
5538
|
useAccessibleDescription((_props$environment = props.environment) == null ? void 0 : _props$environment.document, props.removeElementDescription);
|
|
5509
|
-
|
|
5510
|
-
if (activeIndex !== -1 && previousActiveIndexRef.current !== -1 && activeIndex !== previousActiveIndexRef.current || previousItemsLengthRef.current === items.length + 1) {
|
|
5511
|
-
var _itemRefs$current$ele;
|
|
5512
|
-
(_itemRefs$current$ele = itemRefs.current[elementIds.getTagId(activeIndex)]) == null || _itemRefs$current$ele.focus();
|
|
5513
|
-
}
|
|
5514
|
-
previousActiveIndexRef.current = activeIndex;
|
|
5515
|
-
previousItemsLengthRef.current = items.length;
|
|
5516
|
-
}, [activeIndex, elementIds, items]);
|
|
5539
|
+
var itemRefs = useRovingTagFocus(activeIndex, items.length, elementIds.getTagId);
|
|
5517
5540
|
|
|
5518
5541
|
/* Getter functions */
|
|
5519
5542
|
|
|
@@ -5581,7 +5604,7 @@
|
|
|
5581
5604
|
itemRefs.current[tagId] = itemNode;
|
|
5582
5605
|
}
|
|
5583
5606
|
}), _extends2['aria-labelledby'] = tagId, _extends2.role = 'option', _extends2.id = tagId, _extends2.onClick = callAllEventHandlers$1(onClick, handleClick), _extends2.tabIndex = latestState.activeIndex === index ? 0 : -1, _extends2), rest);
|
|
5584
|
-
}, [dispatch, elementIds, latest]);
|
|
5607
|
+
}, [dispatch, elementIds, latest, itemRefs]);
|
|
5585
5608
|
var getTagRemoveProps = React.useCallback(function (options) {
|
|
5586
5609
|
var index = options.index,
|
|
5587
5610
|
onClick = options.onClick,
|