Skip to content

Commit 4f6b763

Browse files
committed
Fix for useId not available in React 16
1 parent 0c175f5 commit 4f6b763

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

components/dash-core-components/package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/dash-core-components/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
"@types/ramda": "^0.31.0",
7777
"@types/react": "^16.14.8",
7878
"@types/react-dom": "^16.9.13",
79+
"@types/uniqid": "^5.3.4",
7980
"@typescript-eslint/eslint-plugin": "^5.59.7",
8081
"@typescript-eslint/parser": "^5.59.7",
8182
"babel-loader": "^9.2.1",

components/dash-core-components/src/components/Input.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import {pick} from 'ramda';
22
import React, {
3+
InputHTMLAttributes,
34
KeyboardEvent,
45
KeyboardEventHandler,
56
useCallback,
67
useEffect,
78
useRef,
89
useState,
9-
useId,
1010
} from 'react';
11+
import uniqid from 'uniqid';
1112
import fastIsNumeric from 'fast-isnumeric';
1213
import LoadingElement from '../utils/_LoadingElement';
1314
import './css/input.css';
@@ -330,7 +331,7 @@ function Input({
330331
const input = useRef(document.createElement('input'));
331332
const [value, setValue] = useState<InputProps['value']>(props.value);
332333
const [pendingEvent, setPendingEvent] = useState<number>();
333-
const inputId = useId();
334+
const inputId = useState(() => uniqid('input-'))[0];
334335

335336
const valprops =
336337
props.type === HTMLInputTypes.number ? {} : {value: value ?? ''};
@@ -401,7 +402,11 @@ function Input({
401402
value = convert(value);
402403

403404
if (!isEquivalent(base, value)) {
404-
input.current.value = `${value}` ?? '';
405+
if (typeof value === 'undefined') {
406+
input.current.value = '';
407+
} else {
408+
input.current.value = `${value}`;
409+
}
405410
}
406411
},
407412
[]
@@ -490,7 +495,10 @@ function Input({
490495
}
491496
}, [value, props.debounce, props.type]);
492497

493-
const pickedInputs = pick(inputProps, props);
498+
const pickedInputs = pick(
499+
inputProps,
500+
props
501+
) as InputHTMLAttributes<HTMLInputElement>;
494502

495503
const isNumberInput = props.type === HTMLInputTypes.number;
496504
const currentNumericValue = convert(input.current.value || '0');

0 commit comments

Comments
 (0)