diff --git a/packages/ui-components/src/components/CheckboxGroup/CheckboxGroup.component.tsx b/packages/ui-components/src/components/CheckboxGroup/CheckboxGroup.component.tsx index 0f976baf8e..929e4ec8e6 100644 --- a/packages/ui-components/src/components/CheckboxGroup/CheckboxGroup.component.tsx +++ b/packages/ui-components/src/components/CheckboxGroup/CheckboxGroup.component.tsx @@ -83,11 +83,12 @@ export const CheckboxGroup = ({ return !(typeof str === "string" && str.trim().length === 0) } - const uniqueId = () => "juno-checkboxgroup-" + useId() + const generatedName = useId() + const generatedId = useId() // Create unique identifiers for use with name and id of the group: - const groupName = name || uniqueId() - const groupId = id || uniqueId() + const groupName = name || "juno-checkboxgroup-" + generatedName + const groupId = id || "juno-checkboxgroup-" + generatedId // Init state variables: const [selectedOptions, setSelectedOptions] = useState(selected) diff --git a/packages/ui-components/src/components/ComboBox/ComboBox.component.tsx b/packages/ui-components/src/components/ComboBox/ComboBox.component.tsx index 5dacc809b2..ad117ef5b3 100644 --- a/packages/ui-components/src/components/ComboBox/ComboBox.component.tsx +++ b/packages/ui-components/src/components/ComboBox/ComboBox.component.tsx @@ -223,8 +223,9 @@ export const ComboBox = ({ return !(typeof str === "string" && str.trim().length === 0) } - const theId = id || "juno-combobox-" + useId() + const generatedId = useId() const helptextId = "juno-combobox-helptext-" + useId() + const theId = id || "juno-combobox-" + generatedId const [isOpen, setIsOpen] = useState(false) const [optionValuesAndLabels, setOptionValuesAndLabels] = useState( diff --git a/packages/ui-components/src/components/RadioGroup/RadioGroup.component.tsx b/packages/ui-components/src/components/RadioGroup/RadioGroup.component.tsx index 6a4a45e634..dd1bb66dcf 100644 --- a/packages/ui-components/src/components/RadioGroup/RadioGroup.component.tsx +++ b/packages/ui-components/src/components/RadioGroup/RadioGroup.component.tsx @@ -99,11 +99,12 @@ export const RadioGroup = ({ return !(typeof str === "string" && str.trim().length === 0) } - const uniqueId = () => "juno-radiogroup-" + useId() + const generatedName = useId() + const generatedId = useId() // Create unique identifiers for use with name and id of the group: - const groupName = name || uniqueId() - const groupId = id || uniqueId() + const groupName = name || "juno-radiogroup-" + generatedName + const groupId = id || "juno-radiogroup-" + generatedId const [selectedValue, setSelectedValue] = useState(selected) const [isValid, setIsValid] = useState(false) diff --git a/packages/ui-components/src/components/SecretText/SecretText.component.tsx b/packages/ui-components/src/components/SecretText/SecretText.component.tsx index 34b996d244..b5253de67b 100644 --- a/packages/ui-components/src/components/SecretText/SecretText.component.tsx +++ b/packages/ui-components/src/components/SecretText/SecretText.component.tsx @@ -116,8 +116,8 @@ export const SecretText = ({ return !(typeof str === "string" && str.trim().length === 0) } - const uniqueId = () => "juno-secrettext-" + useId() - const theId = id || uniqueId() + const generatedId = useId() + const theId = id || "juno-secrettext-" + generatedId const [isRevealed, setIsRevealed] = useState(false) const [val, setVal] = useState("") diff --git a/packages/ui-components/src/components/Select/Select.component.tsx b/packages/ui-components/src/components/Select/Select.component.tsx index ac023e217e..0d4cbbba26 100644 --- a/packages/ui-components/src/components/Select/Select.component.tsx +++ b/packages/ui-components/src/components/Select/Select.component.tsx @@ -198,11 +198,11 @@ export const Select = ({ return !(typeof value === "string" && value.trim().length === 0) } - const uniqueId = () => "juno-select-" + useId() + const generatedId = useId() + const helptextId = "juno-select-helptext-" + useId() const [isOpen, setIsOpen] = useState(false) - const theId = id || uniqueId() - const helptextId = "juno-select-helptext-" + useId() + const theId = id || "juno-select-" + generatedId const [optionValuesAndLabels, setOptionValuesAndLabels] = useState(new Map()) const [hasError, setHasError] = useState(false) diff --git a/packages/ui-components/src/components/Switch/Switch.component.tsx b/packages/ui-components/src/components/Switch/Switch.component.tsx index b958feffdf..74bf2b5c18 100644 --- a/packages/ui-components/src/components/Switch/Switch.component.tsx +++ b/packages/ui-components/src/components/Switch/Switch.component.tsx @@ -230,7 +230,7 @@ export const Switch = ({ wrapperClassName = "", ...props }: SwitchProps): ReactNode => { - const generateUniqueId = (): string => "juno-switch-" + useId() + const generatedId = useId() const [isOn, setIsOn] = useState(on) const [isInvalid, setIsInvalid] = useState(false) @@ -264,7 +264,7 @@ export const Switch = ({ if (onChange) onChange(event as unknown as ChangeEvent) } - const generatedId: string = id || generateUniqueId() + const theId: string = id || "juno-switch-" + generatedId return (
@@ -279,7 +279,7 @@ export const Switch = ({ type="button" role="switch" name={name} - id={generatedId} + id={theId} aria-checked={isOn} disabled={disabled} onClick={handleSwitchClick} @@ -301,7 +301,7 @@ export const Switch = ({ > -