carbon-react 123.10.0 → 123.10.1
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/esm/__internal__/checkable-input/hidden-checkable-input.component.js +1 -0
- package/esm/__internal__/focus-trap/focus-trap-utils.js +3 -2
- package/esm/__internal__/focus-trap/focus-trap.component.js +11 -10
- package/esm/__internal__/input/input.component.js +1 -0
- package/esm/components/select/filterable-select/filterable-select.component.js +20 -11
- package/esm/components/select/multi-select/multi-select.component.js +23 -14
- package/esm/components/select/simple-select/simple-select.component.js +16 -7
- package/lib/__internal__/checkable-input/hidden-checkable-input.component.js +1 -0
- package/lib/__internal__/focus-trap/focus-trap-utils.js +3 -2
- package/lib/__internal__/focus-trap/focus-trap.component.js +11 -10
- package/lib/__internal__/input/input.component.js +1 -0
- package/lib/components/select/filterable-select/filterable-select.component.js +20 -11
- package/lib/components/select/multi-select/multi-select.component.js +23 -14
- package/lib/components/select/simple-select/simple-select.component.js +16 -7
- package/package.json +1 -1
|
@@ -62,6 +62,7 @@ const HiddenCheckableInput = /*#__PURE__*/React.forwardRef(({
|
|
|
62
62
|
"aria-describedby": combinedDescription,
|
|
63
63
|
"aria-labelledby": ariaLabelledBy,
|
|
64
64
|
autoFocus: autoFocus,
|
|
65
|
+
"data-has-autofocus": autoFocus ? true : undefined,
|
|
65
66
|
"aria-checked": checked,
|
|
66
67
|
checked: checked,
|
|
67
68
|
name: name,
|
|
@@ -90,7 +90,8 @@ const onTabGuardFocus = (trapWrappers, focusableSelectors, position) => guardWra
|
|
|
90
90
|
const isTop = position === "top";
|
|
91
91
|
const currentIndex = trapWrappers.indexOf(guardWrapperRef);
|
|
92
92
|
let index = currentIndex;
|
|
93
|
-
let nextWrapper
|
|
93
|
+
let nextWrapper;
|
|
94
|
+
let allFocusableElementsInNextWrapper;
|
|
94
95
|
do {
|
|
95
96
|
index += isTop ? -1 : 1;
|
|
96
97
|
if (index < 0) {
|
|
@@ -100,7 +101,7 @@ const onTabGuardFocus = (trapWrappers, focusableSelectors, position) => guardWra
|
|
|
100
101
|
index -= trapWrappers.length;
|
|
101
102
|
}
|
|
102
103
|
nextWrapper = trapWrappers[index];
|
|
103
|
-
allFocusableElementsInNextWrapper = nextWrapper?.current?.querySelectorAll(focusableSelectors || defaultFocusableSelectors);
|
|
104
|
+
allFocusableElementsInNextWrapper = Array.from(nextWrapper?.current?.querySelectorAll(focusableSelectors || defaultFocusableSelectors) || /* istanbul ignore next */[]).filter(el => Number(el.tabIndex) !== -1);
|
|
104
105
|
} while (index !== currentIndex && !allFocusableElementsInNextWrapper?.length);
|
|
105
106
|
const toFocus = allFocusableElementsInNextWrapper?.[isTop ? allFocusableElementsInNextWrapper.length - 1 : 0];
|
|
106
107
|
if (isRadio(toFocus)) {
|
|
@@ -74,16 +74,6 @@ const FocusTrap = ({
|
|
|
74
74
|
}, [additionalWrapperRefs, onTabGuardTopFocus, onTabGuardBottomFocus]);
|
|
75
75
|
const shouldSetFocus = autoFocus && isOpen && isAnimationComplete;
|
|
76
76
|
const prevShouldSetFocus = usePrevious(shouldSetFocus);
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
if (shouldSetFocus && !prevShouldSetFocus) {
|
|
79
|
-
const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
|
|
80
|
-
const elementToFocus = candidateFirstElement || wrapperRef.current;
|
|
81
|
-
// istanbul ignore else
|
|
82
|
-
if (elementToFocus) {
|
|
83
|
-
setElementFocus(elementToFocus);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}, [shouldSetFocus, prevShouldSetFocus, focusFirstElement, wrapperRef]);
|
|
87
77
|
const getFocusableElements = useCallback(selector => {
|
|
88
78
|
const elements = [];
|
|
89
79
|
trapWrappers.forEach(ref => {
|
|
@@ -94,6 +84,17 @@ const FocusTrap = ({
|
|
|
94
84
|
});
|
|
95
85
|
return elements;
|
|
96
86
|
}, [trapWrappers]);
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (shouldSetFocus && !prevShouldSetFocus) {
|
|
89
|
+
const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
|
|
90
|
+
const autoFocusedElement = getFocusableElements(defaultFocusableSelectors).find(el => el.getAttribute("data-has-autofocus") === "true");
|
|
91
|
+
const elementToFocus = candidateFirstElement || autoFocusedElement || wrapperRef.current;
|
|
92
|
+
// istanbul ignore else
|
|
93
|
+
if (elementToFocus) {
|
|
94
|
+
setElementFocus(elementToFocus);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}, [shouldSetFocus, prevShouldSetFocus, getFocusableElements, focusFirstElement, wrapperRef]);
|
|
97
98
|
useEffect(() => {
|
|
98
99
|
const trapFn = ev => {
|
|
99
100
|
// block focus trap from working if it's not the topmost trap, or is currently closed
|
|
@@ -131,6 +131,7 @@ const Input = /*#__PURE__*/React.forwardRef(({
|
|
|
131
131
|
}
|
|
132
132
|
const combinedDescription = descriptionList.length ? descriptionList.filter(Boolean).join(" ") : undefined;
|
|
133
133
|
return /*#__PURE__*/React.createElement(StyledInput, _extends({}, rest, {
|
|
134
|
+
"data-has-autofocus": autoFocus ? true : undefined,
|
|
134
135
|
"aria-describedby": combinedDescription,
|
|
135
136
|
"aria-labelledby": ariaLabelledBy,
|
|
136
137
|
align: align,
|
|
@@ -77,6 +77,7 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
77
77
|
id: inputId.current,
|
|
78
78
|
label
|
|
79
79
|
});
|
|
80
|
+
const focusTimer = useRef(null);
|
|
80
81
|
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
81
82
|
deprecateInputRefWarnTriggered = true;
|
|
82
83
|
Logger.deprecate("The `inputRef` prop in `Filterable Select` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
@@ -306,18 +307,26 @@ const FilterableSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
306
307
|
function handleTextboxFocus(event) {
|
|
307
308
|
const triggerFocus = () => onFocus?.(event);
|
|
308
309
|
if (openOnFocus) {
|
|
309
|
-
|
|
310
|
-
|
|
310
|
+
if (focusTimer.current) {
|
|
311
|
+
clearTimeout(focusTimer.current);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
315
|
+
// whereby the select list isn't visible when the select is auto focused straight away
|
|
316
|
+
focusTimer.current = setTimeout(() => {
|
|
317
|
+
setOpen(isAlreadyOpen => {
|
|
318
|
+
if (isAlreadyOpen) {
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
if (onFocus && !isInputFocused.current) {
|
|
322
|
+
triggerFocus();
|
|
323
|
+
isInputFocused.current = true;
|
|
324
|
+
}
|
|
325
|
+
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
326
|
+
return false;
|
|
327
|
+
}
|
|
311
328
|
return true;
|
|
312
|
-
}
|
|
313
|
-
if (onFocus && !isInputFocused.current) {
|
|
314
|
-
triggerFocus();
|
|
315
|
-
isInputFocused.current = true;
|
|
316
|
-
}
|
|
317
|
-
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
318
|
-
return false;
|
|
319
|
-
}
|
|
320
|
-
return true;
|
|
329
|
+
});
|
|
321
330
|
});
|
|
322
331
|
} else if (onFocus && !isInputFocused.current) {
|
|
323
332
|
triggerFocus();
|
|
@@ -82,6 +82,7 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
82
82
|
id: inputId.current,
|
|
83
83
|
label
|
|
84
84
|
});
|
|
85
|
+
const focusTimer = useRef(null);
|
|
85
86
|
const actualValue = isControlled.current ? value : selectedValue;
|
|
86
87
|
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
87
88
|
deprecateInputRefWarnTriggered = true;
|
|
@@ -312,21 +313,29 @@ const MultiSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
312
313
|
function handleTextboxFocus(event) {
|
|
313
314
|
const triggerFocus = () => onFocus?.(event);
|
|
314
315
|
if (openOnFocus) {
|
|
315
|
-
|
|
316
|
-
|
|
316
|
+
if (focusTimer.current) {
|
|
317
|
+
clearTimeout(focusTimer.current);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
321
|
+
// whereby the select list isn't visible when the select is auto focused straight away
|
|
322
|
+
focusTimer.current = setTimeout(() => {
|
|
323
|
+
setOpenState(isAlreadyOpen => {
|
|
324
|
+
if (isAlreadyOpen) {
|
|
325
|
+
return true;
|
|
326
|
+
}
|
|
327
|
+
if (onOpen) {
|
|
328
|
+
onOpen();
|
|
329
|
+
}
|
|
330
|
+
if (onFocus && !isInputFocused.current) {
|
|
331
|
+
triggerFocus();
|
|
332
|
+
isInputFocused.current = true;
|
|
333
|
+
}
|
|
334
|
+
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
317
337
|
return true;
|
|
318
|
-
}
|
|
319
|
-
if (onOpen) {
|
|
320
|
-
onOpen();
|
|
321
|
-
}
|
|
322
|
-
if (onFocus && !isInputFocused.current) {
|
|
323
|
-
triggerFocus();
|
|
324
|
-
isInputFocused.current = true;
|
|
325
|
-
}
|
|
326
|
-
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
return true;
|
|
338
|
+
});
|
|
330
339
|
});
|
|
331
340
|
} else if (onFocus && !isInputFocused.current) {
|
|
332
341
|
triggerFocus();
|
|
@@ -72,6 +72,7 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
72
72
|
id: inputId.current,
|
|
73
73
|
label
|
|
74
74
|
});
|
|
75
|
+
const focusTimer = useRef(null);
|
|
75
76
|
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
76
77
|
deprecateInputRefWarnTriggered = true;
|
|
77
78
|
Logger.deprecate("The `inputRef` prop in `Simple Select` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
@@ -235,14 +236,22 @@ const SimpleSelect = /*#__PURE__*/React.forwardRef(({
|
|
|
235
236
|
return;
|
|
236
237
|
}
|
|
237
238
|
if (openOnFocus) {
|
|
238
|
-
|
|
239
|
-
|
|
239
|
+
if (focusTimer.current) {
|
|
240
|
+
clearTimeout(focusTimer.current);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
244
|
+
// whereby the select list isn't visible when the select is auto focused straight away
|
|
245
|
+
focusTimer.current = setTimeout(() => {
|
|
246
|
+
setOpenState(isAlreadyOpen => {
|
|
247
|
+
if (isAlreadyOpen) {
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
if (onOpen) {
|
|
251
|
+
onOpen();
|
|
252
|
+
}
|
|
240
253
|
return true;
|
|
241
|
-
}
|
|
242
|
-
if (onOpen) {
|
|
243
|
-
onOpen();
|
|
244
|
-
}
|
|
245
|
-
return true;
|
|
254
|
+
});
|
|
246
255
|
});
|
|
247
256
|
}
|
|
248
257
|
}
|
|
@@ -71,6 +71,7 @@ const HiddenCheckableInput = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
71
71
|
"aria-describedby": combinedDescription,
|
|
72
72
|
"aria-labelledby": ariaLabelledBy,
|
|
73
73
|
autoFocus: autoFocus,
|
|
74
|
+
"data-has-autofocus": autoFocus ? true : undefined,
|
|
74
75
|
"aria-checked": checked,
|
|
75
76
|
checked: checked,
|
|
76
77
|
name: name,
|
|
@@ -99,7 +99,8 @@ const onTabGuardFocus = (trapWrappers, focusableSelectors, position) => guardWra
|
|
|
99
99
|
const isTop = position === "top";
|
|
100
100
|
const currentIndex = trapWrappers.indexOf(guardWrapperRef);
|
|
101
101
|
let index = currentIndex;
|
|
102
|
-
let nextWrapper
|
|
102
|
+
let nextWrapper;
|
|
103
|
+
let allFocusableElementsInNextWrapper;
|
|
103
104
|
do {
|
|
104
105
|
index += isTop ? -1 : 1;
|
|
105
106
|
if (index < 0) {
|
|
@@ -109,7 +110,7 @@ const onTabGuardFocus = (trapWrappers, focusableSelectors, position) => guardWra
|
|
|
109
110
|
index -= trapWrappers.length;
|
|
110
111
|
}
|
|
111
112
|
nextWrapper = trapWrappers[index];
|
|
112
|
-
allFocusableElementsInNextWrapper = nextWrapper?.current?.querySelectorAll(focusableSelectors || defaultFocusableSelectors);
|
|
113
|
+
allFocusableElementsInNextWrapper = Array.from(nextWrapper?.current?.querySelectorAll(focusableSelectors || defaultFocusableSelectors) || /* istanbul ignore next */[]).filter(el => Number(el.tabIndex) !== -1);
|
|
113
114
|
} while (index !== currentIndex && !allFocusableElementsInNextWrapper?.length);
|
|
114
115
|
const toFocus = allFocusableElementsInNextWrapper?.[isTop ? allFocusableElementsInNextWrapper.length - 1 : 0];
|
|
115
116
|
if (isRadio(toFocus)) {
|
|
@@ -84,16 +84,6 @@ const FocusTrap = ({
|
|
|
84
84
|
}, [additionalWrapperRefs, onTabGuardTopFocus, onTabGuardBottomFocus]);
|
|
85
85
|
const shouldSetFocus = autoFocus && isOpen && isAnimationComplete;
|
|
86
86
|
const prevShouldSetFocus = (0, _usePrevious.default)(shouldSetFocus);
|
|
87
|
-
(0, _react.useEffect)(() => {
|
|
88
|
-
if (shouldSetFocus && !prevShouldSetFocus) {
|
|
89
|
-
const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
|
|
90
|
-
const elementToFocus = candidateFirstElement || wrapperRef.current;
|
|
91
|
-
// istanbul ignore else
|
|
92
|
-
if (elementToFocus) {
|
|
93
|
-
(0, _focusTrapUtils.setElementFocus)(elementToFocus);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}, [shouldSetFocus, prevShouldSetFocus, focusFirstElement, wrapperRef]);
|
|
97
87
|
const getFocusableElements = (0, _react.useCallback)(selector => {
|
|
98
88
|
const elements = [];
|
|
99
89
|
trapWrappers.forEach(ref => {
|
|
@@ -104,6 +94,17 @@ const FocusTrap = ({
|
|
|
104
94
|
});
|
|
105
95
|
return elements;
|
|
106
96
|
}, [trapWrappers]);
|
|
97
|
+
(0, _react.useEffect)(() => {
|
|
98
|
+
if (shouldSetFocus && !prevShouldSetFocus) {
|
|
99
|
+
const candidateFirstElement = focusFirstElement && "current" in focusFirstElement ? focusFirstElement.current : focusFirstElement;
|
|
100
|
+
const autoFocusedElement = getFocusableElements(_focusTrapUtils.defaultFocusableSelectors).find(el => el.getAttribute("data-has-autofocus") === "true");
|
|
101
|
+
const elementToFocus = candidateFirstElement || autoFocusedElement || wrapperRef.current;
|
|
102
|
+
// istanbul ignore else
|
|
103
|
+
if (elementToFocus) {
|
|
104
|
+
(0, _focusTrapUtils.setElementFocus)(elementToFocus);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}, [shouldSetFocus, prevShouldSetFocus, getFocusableElements, focusFirstElement, wrapperRef]);
|
|
107
108
|
(0, _react.useEffect)(() => {
|
|
108
109
|
const trapFn = ev => {
|
|
109
110
|
// block focus trap from working if it's not the topmost trap, or is currently closed
|
|
@@ -140,6 +140,7 @@ const Input = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
140
140
|
}
|
|
141
141
|
const combinedDescription = descriptionList.length ? descriptionList.filter(Boolean).join(" ") : undefined;
|
|
142
142
|
return /*#__PURE__*/_react.default.createElement(_input.default, _extends({}, rest, {
|
|
143
|
+
"data-has-autofocus": autoFocus ? true : undefined,
|
|
143
144
|
"aria-describedby": combinedDescription,
|
|
144
145
|
"aria-labelledby": ariaLabelledBy,
|
|
145
146
|
align: align,
|
|
@@ -86,6 +86,7 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
86
86
|
id: inputId.current,
|
|
87
87
|
label
|
|
88
88
|
});
|
|
89
|
+
const focusTimer = (0, _react.useRef)(null);
|
|
89
90
|
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
90
91
|
deprecateInputRefWarnTriggered = true;
|
|
91
92
|
_logger.default.deprecate("The `inputRef` prop in `Filterable Select` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
@@ -315,18 +316,26 @@ const FilterableSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
315
316
|
function handleTextboxFocus(event) {
|
|
316
317
|
const triggerFocus = () => onFocus?.(event);
|
|
317
318
|
if (openOnFocus) {
|
|
318
|
-
|
|
319
|
-
|
|
319
|
+
if (focusTimer.current) {
|
|
320
|
+
clearTimeout(focusTimer.current);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
324
|
+
// whereby the select list isn't visible when the select is auto focused straight away
|
|
325
|
+
focusTimer.current = setTimeout(() => {
|
|
326
|
+
setOpen(isAlreadyOpen => {
|
|
327
|
+
if (isAlreadyOpen) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
if (onFocus && !isInputFocused.current) {
|
|
331
|
+
triggerFocus();
|
|
332
|
+
isInputFocused.current = true;
|
|
333
|
+
}
|
|
334
|
+
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
320
337
|
return true;
|
|
321
|
-
}
|
|
322
|
-
if (onFocus && !isInputFocused.current) {
|
|
323
|
-
triggerFocus();
|
|
324
|
-
isInputFocused.current = true;
|
|
325
|
-
}
|
|
326
|
-
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
327
|
-
return false;
|
|
328
|
-
}
|
|
329
|
-
return true;
|
|
338
|
+
});
|
|
330
339
|
});
|
|
331
340
|
} else if (onFocus && !isInputFocused.current) {
|
|
332
341
|
triggerFocus();
|
|
@@ -91,6 +91,7 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
91
91
|
id: inputId.current,
|
|
92
92
|
label
|
|
93
93
|
});
|
|
94
|
+
const focusTimer = (0, _react.useRef)(null);
|
|
94
95
|
const actualValue = isControlled.current ? value : selectedValue;
|
|
95
96
|
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
96
97
|
deprecateInputRefWarnTriggered = true;
|
|
@@ -321,21 +322,29 @@ const MultiSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
321
322
|
function handleTextboxFocus(event) {
|
|
322
323
|
const triggerFocus = () => onFocus?.(event);
|
|
323
324
|
if (openOnFocus) {
|
|
324
|
-
|
|
325
|
-
|
|
325
|
+
if (focusTimer.current) {
|
|
326
|
+
clearTimeout(focusTimer.current);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
330
|
+
// whereby the select list isn't visible when the select is auto focused straight away
|
|
331
|
+
focusTimer.current = setTimeout(() => {
|
|
332
|
+
setOpenState(isAlreadyOpen => {
|
|
333
|
+
if (isAlreadyOpen) {
|
|
334
|
+
return true;
|
|
335
|
+
}
|
|
336
|
+
if (onOpen) {
|
|
337
|
+
onOpen();
|
|
338
|
+
}
|
|
339
|
+
if (onFocus && !isInputFocused.current) {
|
|
340
|
+
triggerFocus();
|
|
341
|
+
isInputFocused.current = true;
|
|
342
|
+
}
|
|
343
|
+
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
326
346
|
return true;
|
|
327
|
-
}
|
|
328
|
-
if (onOpen) {
|
|
329
|
-
onOpen();
|
|
330
|
-
}
|
|
331
|
-
if (onFocus && !isInputFocused.current) {
|
|
332
|
-
triggerFocus();
|
|
333
|
-
isInputFocused.current = true;
|
|
334
|
-
}
|
|
335
|
-
if (isMouseDownReported.current && !isMouseDownOnInput.current) {
|
|
336
|
-
return false;
|
|
337
|
-
}
|
|
338
|
-
return true;
|
|
347
|
+
});
|
|
339
348
|
});
|
|
340
349
|
} else if (onFocus && !isInputFocused.current) {
|
|
341
350
|
triggerFocus();
|
|
@@ -81,6 +81,7 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
81
81
|
id: inputId.current,
|
|
82
82
|
label
|
|
83
83
|
});
|
|
84
|
+
const focusTimer = (0, _react.useRef)(null);
|
|
84
85
|
if (!deprecateInputRefWarnTriggered && inputRef) {
|
|
85
86
|
deprecateInputRefWarnTriggered = true;
|
|
86
87
|
_logger.default.deprecate("The `inputRef` prop in `Simple Select` component is deprecated and will soon be removed. Please use `ref` instead.");
|
|
@@ -244,14 +245,22 @@ const SimpleSelect = /*#__PURE__*/_react.default.forwardRef(({
|
|
|
244
245
|
return;
|
|
245
246
|
}
|
|
246
247
|
if (openOnFocus) {
|
|
247
|
-
|
|
248
|
-
|
|
248
|
+
if (focusTimer.current) {
|
|
249
|
+
clearTimeout(focusTimer.current);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// we need to use a timeout here as there is a race condition when rendered in a modal
|
|
253
|
+
// whereby the select list isn't visible when the select is auto focused straight away
|
|
254
|
+
focusTimer.current = setTimeout(() => {
|
|
255
|
+
setOpenState(isAlreadyOpen => {
|
|
256
|
+
if (isAlreadyOpen) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (onOpen) {
|
|
260
|
+
onOpen();
|
|
261
|
+
}
|
|
249
262
|
return true;
|
|
250
|
-
}
|
|
251
|
-
if (onOpen) {
|
|
252
|
-
onOpen();
|
|
253
|
-
}
|
|
254
|
-
return true;
|
|
263
|
+
});
|
|
255
264
|
});
|
|
256
265
|
}
|
|
257
266
|
}
|