1
- import { ReactElement } from 'react'
1
+ import { ReactElement , useMemo } from 'react'
2
2
3
3
import { Tooltip } from '@Common/Tooltip'
4
4
import { Icon } from '@Shared/Components'
5
5
import { ComponentSizeType } from '@Shared/constants'
6
+ import { getUniqueId } from '@Shared/Helpers'
6
7
7
8
import { ConditionalWrap } from '../Helper'
8
9
import { COMPONENT_SIZE_TO_ICON_CLASS_MAP , COMPONENT_SIZE_TO_SEGMENT_CLASS_MAP } from './constants'
@@ -24,6 +25,8 @@ const Segment = ({
24
25
size,
25
26
disabled,
26
27
} : SegmentProps ) => {
28
+ const inputId = useMemo ( getUniqueId , [ ] )
29
+
27
30
const { value, icon, isError, label, tooltipProps, ariaLabel } = segment
28
31
const handleChange = ( ) => {
29
32
onChange ( segment )
@@ -32,13 +35,13 @@ const Segment = ({
32
35
return (
33
36
< ConditionalWrap key = { value } condition = { ! ! tooltipProps ?. content } wrap = { wrapWithTooltip ( tooltipProps ) } >
34
37
< div
35
- className = { `dc__position-rel dc__text-center ${ fullWidth ? 'flex-grow-1' : '' } ` }
38
+ className = { `dc__position-rel dc__text-center dc__no-shrink ${ fullWidth ? 'flex-grow-1' : '' } ` }
36
39
ref = { selectedSegmentRef }
37
40
>
38
41
< input
39
42
type = "radio"
40
43
value = { value }
41
- id = { ` ${ name } - ${ value } ` }
44
+ id = { inputId }
42
45
name = { name }
43
46
onChange = { handleChange }
44
47
checked = { isSelected }
@@ -47,7 +50,7 @@ const Segment = ({
47
50
/>
48
51
49
52
< label
50
- htmlFor = { ` ${ name } - ${ value } ` }
53
+ htmlFor = { inputId }
51
54
className = { `pointer m-0 flex ${ ! fullWidth ? 'left' : '' } dc__gap-4 br-4 segmented-control__segment segmented-control__segment--${ size } ${ isSelected ? 'fw-6 segmented-control__segment--selected' : 'fw-4' } ${ segment . isError ? 'cr-5' : 'cn-9' } ${ disabled ? 'cursor-not-allowed' : '' } ${ COMPONENT_SIZE_TO_SEGMENT_CLASS_MAP [ size ] } ` }
52
55
aria-label = { ariaLabel }
53
56
>
0 commit comments