From 470f28c7520f377eac279c1ad13e0d385800691c Mon Sep 17 00:00:00 2001 From: JeremyRH Date: Tue, 13 Jan 2026 16:12:04 -0800 Subject: [PATCH 1/2] fix: make unique id generation come from context when provided --- .../Checkbox/CheckboxBooleanInput.tsx | 6 +- src/components/Form/FormChoice.js | 93 +++++++++---------- .../HasManyFields/HasManyFieldsRow.tsx | 6 +- src/components/HelpBubble/HelpBubble.tsx | 4 +- src/components/List/List.tsx | 4 +- src/components/List/ListItem.tsx | 4 +- .../List/components/FilterHeader.tsx | 6 +- src/components/List/components/SortHeader.tsx | 6 +- src/components/Table/SortableTable.js | 45 +++++---- src/components/Tooltip/TooltipButton.tsx | 6 +- src/components/Tree/TreeItem.tsx | 6 +- .../TruncatedText/TruncatedText.tsx | 7 +- src/context.tsx | 11 +++ src/index.ts | 1 + src/util/uniqueId.ts | 8 -- src/util/uniqueId.tsx | 17 ++++ 16 files changed, 125 insertions(+), 105 deletions(-) create mode 100644 src/context.tsx delete mode 100644 src/util/uniqueId.ts create mode 100644 src/util/uniqueId.tsx diff --git a/src/components/Checkbox/CheckboxBooleanInput.tsx b/src/components/Checkbox/CheckboxBooleanInput.tsx index 28093f409..135044bf8 100644 --- a/src/components/Checkbox/CheckboxBooleanInput.tsx +++ b/src/components/Checkbox/CheckboxBooleanInput.tsx @@ -1,7 +1,7 @@ import classnames from 'classnames'; -import React, { useState } from 'react'; +import React from 'react'; import type { InputProps } from 'reactstrap'; -import { getUniqueId } from '../../util/uniqueId'; +import { useUniqueId } from '../../util/uniqueId'; import FormGroup from '../Form/FormGroup'; import Input from '../Input/Input'; import Label from '../Label/Label'; @@ -19,7 +19,7 @@ function CheckboxBooleanInput({ value, ...inputProps }: CheckboxBooleanInputProps) { - const [generatedId] = useState(() => getUniqueId('checkbox-boolean-input-')); + const generatedId = useUniqueId('checkbox-boolean-input-'); const id = inputProps.id || generatedId; const classNames = classnames('pt-2', className); return ( diff --git a/src/components/Form/FormChoice.js b/src/components/Form/FormChoice.js index 974126a07..212f12ea5 100644 --- a/src/components/Form/FormChoice.js +++ b/src/components/Form/FormChoice.js @@ -1,63 +1,56 @@ import classname from 'classnames'; import React from 'react'; -import { getUniqueId } from '../../util/uniqueId'; +import { useUniqueId } from '../../util/uniqueId'; import Input from '../Input/Input'; import Label from '../Label/Label'; import FormGroup from './FormGroup'; -class FormChoice extends React.Component { - constructor(props) { - super(props); - this.id = props.id || getUniqueId('form-choice-'); - } - - render() { - /* eslint-disable-next-line @typescript-eslint/no-unused-vars -- Let's figure out a better way to omit props for this scenario */ - const { id, inline, disabled, children, containerClassName, type, value, ...attributes } = - this.props; - - if (type === 'select') { - return ( - - ); - } - - const containerClasses = classname({ 'form-check-inline': inline }, containerClassName); - - const computedValue = value || children; - - const item = ( -
- - -
- ); +function FormChoice({ id, inline, disabled, children, containerClassName, type, value, ...props }) { + const generatedId = useUniqueId('form-choice-'); + const idToUse = id || generatedId; - if (inline) { - return item; - } + if (type === 'select') { return ( - - {item} - + ); } + + const containerClasses = classname({ 'form-check-inline': inline }, containerClassName); + + const computedValue = value || children; + + const item = ( +
+ + +
+ ); + + if (inline) { + return item; + } + + return ( + + {item} + + ); } export default FormChoice; diff --git a/src/components/HasManyFields/HasManyFieldsRow.tsx b/src/components/HasManyFields/HasManyFieldsRow.tsx index b6456604c..d164d73ec 100644 --- a/src/components/HasManyFields/HasManyFieldsRow.tsx +++ b/src/components/HasManyFields/HasManyFieldsRow.tsx @@ -1,7 +1,7 @@ import { Placement } from '@popperjs/core'; import classnames from 'classnames'; -import React, { useState } from 'react'; -import { getUniqueId } from '../../util/uniqueId'; +import React from 'react'; +import { useUniqueId } from '../../util/uniqueId'; import Button from '../Button/Button'; import ConfirmationButton, { ConfirmationButtonProps } from '../Button/ConfirmationButton'; import Icon from '../Icon/Icon'; @@ -33,7 +33,7 @@ const HasManyFieldsRow = ({ deleteProps, ...props }: HasManyFieldsRowProps) => { - const [id] = useState(() => getUniqueId('hmf-', 1)); + const id = useUniqueId('hmf-', 1); const classNames = classnames('mb-4 gx-0', className); // The `disabled ?